I am trying to populate a drop-down select options list and set a default selected value using ng-model and ng-options.
I have the following code in my view:
<select ng-model="thisTour.site" ng-options="site.name for site in siteList"></select>
And in my controller:
$scope.siteList = [
{ id: 1, name: 'cycling'},
{ id: 2, name: 'walking'},
{ id: 3, name: 'holidays'}
]
$scope.thisTour.site = { id: 2, name: 'walking'};
The list is getting populated with the correct 3 options from the siteList
object, but it is not selecting walking by default as I would expect? Why not?
Now, when I change this:
$scope.thisTour.site = { id: 2, name: 'walking'};
To this:
$scope.thisTour.site = $scope.siteList[1];
Now it works. Why? Isn't it the same thing?