Reputation: 336
I have the following html for drop down.
<select id="selection">
<option value="{{n}}" ng-repeat="n in selections">{{n}}</option>
</select>
where selections is an array of strings
and the array lives in my angularJS
controller.
The initial data for the select options are correct, but When the array is updated by getting assigned as []
and then pushed in some new data, the select options does not update accordingly.
Are there workarounds for this?
Upvotes: 0
Views: 891
Reputation: 2130
Sample controller:
app.controller('MainCtrl', function($scope) {
$scope.items = [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
{ id: 3, name: 'blah' }
];
});
html -
<select ng-model="selectedItem" ng-options="item as item.name for item in items"></select>
use ng-options instead of ng-repeat.
Upvotes: 1