嘗試使用此Jsfiddle demo
這裏
更新代碼Jsfiddle link updated
JS代碼
var app = angular.module('myApp', []);
app.controller('ctrl1', function($scope) {
$scope.rules = [{
name: 'rule1',
id: 1
}, {
name: 'rule2',
id: 2
}];
$scope.data = [];
var dummy = [];
$scope.addText = function(rule) {
dummy.push(rule);
if (dummy.length > 2) {
$scope.data = angular.copy(dummy);
$scope.one = $scope.data[0];
$scope.two = $scope.data[1];
$scope.three = $scope.data[2];
}
}
});
HTML代碼
<div ng-app='myApp'>
<div ng-controller='ctrl1'>
<select ng-options='item.name as item.name for item in rules' ng-model='rule' ng-change='addText(rule)'>
</select>
<hr> Length: {{data.length}}
<hr>
<div ng-if='data.length > 2'>
<input type='text' ng-model='one'>
<input type='text' ng-model='two'>
<input type='text' ng-model='three'>
</div>
</div>
</div>
根據你的問題,我建立這個,但你可以擴大此
添加更多的信息 –
你在哪裏定義obj? –