I have the following problem. In my controller I have this variables:
$scope.types = [
{id: 0, name: $translate.instant("FIRST")},
{id: 1, name: $translate.instant("SECOND")},
{id: 2, name: $translate.instant("THIRD")},
{id: 3, name: $translate.instant("FOURTH")}
];
$scope.itemtype = {};
$scope.itemtype = $scope.types[0];
In my view I have this select
<select class="form-control"
required
ng-model="itemtype"
ng-options="item as item.name for item in types track by item.id">
</select>
I have similar selects that work perfectly, but this isn't working, if I select the second option in the model the old value remains selected, but in the explorer I'm viewing the second option as the selected.
In firebug I'm viewing this output
<select class="form-control ng-pristine ng-valid ng-valid-required ng-touched" ng-options="item as item.name for item in types track by item.id" ng-model="itemtype" required="" tabindex="0" aria-required="false" aria-invalid="false">
<option value="0" label="First">First</option>
<option value="1" label="Second">Second</option>
<option value="2" label="Third"> Third </option>
<option value="3" selected="selected" label="Fourth"> Fourth </option>
</select>
How can I fix it?
Thanks
You used 'select as' and 'track by' together, but API document say:
Do not use select as and track by in the same expression. They are not designed to work together.
Reference:
https://code.angularjs.org/1.3.10/docs/api/ng/directive/select