Select Option Value Not Iterated Dynamically In Ng-repeat
If you look at the below code, how do i differentiate each and every select dropdowns dynamically? All dropdowns are showing the same value if selected. Requirement is I wanted to
Solution 1:
The problem is your selectedItems
is one and you have colors
as array
.
You can have selectedItems
inside colors
like this:
$scope.colors.map(function(obj) {
return obj.selectedItems = {
val: $scope.arr[0]
}
})
Now, change your <select>
like this:
<selectng-model="product.selectedItems.val"ng-init="product.selectedItems.val = product.selectedItems.val + ''"><optionng-repeat="value in arr | limitTo:quantity">{{value}}
</option></select>
And, submit
be like:
$scope.submit = function() {
$scope.colors.forEach(function(obj) {
console.log(obj.selectedItems.val)
})
}
Alternatively, you can make use of $index
inside first ng-repeat
to have selectedItems
seperate than colors
Solution 2:
Provide unique id to select element like id={{$index+1}} to differentiate bewteen all the select dropdowns.
Solution 3:
There were few errors in the code. You have missed 2 commas in $scope.product json .
See updated working fiddle
Post a Comment for "Select Option Value Not Iterated Dynamically In Ng-repeat"