I have a array of objects that I\'m displaying using ng-options, and set ng-model with id. If i add track by
on it, the item can\'t selected, if not add, it wor
According to the documentation of ng-options (rephrased to your example).
This will work:
$scope.country = $scope.countryList[0];
but this will not work:
$scope.country = $scope.countryList[0].id;
In both examples, the track by expression is applied successfully to each country in the countryList array. Because the selected option has been set programmatically in the controller, the track by expression is also applied to the ngModel value. In the first example, the ngModel value is countryList[0] and the track by expression evaluates to countryList[0].id with no issue. In the second example, the ngModel value is countryList[0].id and the track by expression evaluates to countryList[0].id.id (which is undefined). As a result, the model value is not matched against any and the
appears as having no selected value.