Reputation: 105
I have problem with select in angular.
HTML:
<select ng-model="vm.targetClassName" ng-options="item for item in vm.classList">
</select>
CONTROLLER:
vm.targetClassName = 'b';
generalResources.getClasses().then(setClasses);
function setClasses(classes) {
vm.classList = classes.value;
}
After this block of code vm.classList
is containing array of Strings, for example ['a', 'b', 'c']
What I expect is that select has three options, and the 'b'
is selected however I only got select with three options, but nothing is selected.
I checked these values with AngularJS Inspector and it clearly shows that vm.classList
is ['a', 'b', 'c']
and vm.targetClassName
is 'b'
;
How can I fix this problem?
Upvotes: 1
Views: 1256
Reputation: 136174
This issue isn't reproducible with Angular current version 1.6.3. It seems like Angular 1.3 specific issue. Though you could fix this issue by using track by
on ng-options
directive
<select ng-model="vm.targetClassName"
ng-options="item for item in vm.classList track by item">
</select>
Upvotes: 2