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:
<
Since you are using the entire object in your select then when Angular does it's comparison it is going to see if the objects are the same in order to set your select. I believe there is a way to change the functionality in how Angular does it's comparisions but I just loop through the select and do my own comparions similar to the below:
$scope.siteList = [
{ id: 1, name: 'cycling'},
{ id: 2, name: 'walking'},
{ id: 3, name: 'holidays'}
]
angular.forEach($scope.siteList, function(site, index) {
if (site.id == 2) {
$scope.thisTour.site = site;
}
});
This will set the actual object to your variable allowing it to be set in the select.