如果你看下面的代碼,我該如何動態地區分每個選擇下拉菜單?在ng-repeat中動態迭代的選項值
如果選中,所有下拉菜單都顯示相同的值。
要求是我想根據響應結構動態地從1到10選項值(在數組中聲明)中顯示3個下拉列表 - 在這種情況下,有三個產品,因此需要顯示三個動態下拉列表。
實現此目的的有效方法是什麼?
HTML
<div ng-controller="MyCtrl">
<div ng-repeat="product in colors.item">
<div ng-if="quan!=true">
<select ng-model="selectedItems.val" ng-init="selectedItems.val = selectedItems.val + ''">
<option ng-repeat="value in arr | limitTo:quantity">{{value}}</option>
</select>
</div>
</div>
<div>
<a href="#" ng-click="submit(selectedItems.val)">Submit</a>
</div>
</div>
JS
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
myApp.controller('MyCtrl', function MyCtrl($scope) {
$scope.colors = {"category": "students"
"item":[
{
"product":{
"name":"abc",
"age": "24"
}
"boo": true
},
{
"product":{
"name":"def",
"age": "44"
}
},
{
"product":{
"name":"ghi",
"age": "22"
}
}
]};
$scope.quan = false;
$scope.arr = [];
for(var a=1; a<=10; a++) {
$scope.arr.push(a);
}
$scope.selectedItems = {val : $scope.arr[0]};
$scope.quantity = 10;
$scope.submit = function(av){
alert(av);
}
});
爲什麼不使用'NG-options'? – tanmay
試過這個......當加載這個 –
時出現了注射器錯誤什麼是預期行爲? – tanmay