Say i have these options from the database
$scope.options = [
{ id: 192, value: 'Bank 1'},
{ id: 168, value: 'Bank 2'},
{ id: 0, value: 'Bank 3'},
];
and that this code works for setting default values by selecting the array position
<select ng-init="data.bankoptions=options[0]" ng-model="data.bankoptions" ng-options="bank.label for bank in options track by bank.id">
and will display Bank 1 as default
How do i make it to set the default selection according to the object id? by selecting 192, 168 or 0.
Thanks!
var data = {
availableoptions: [],
selectedoption: {}
};
Add data to options
data.availableoptions.push({id: 192, label: 'Bank1'});
Set default selection
data.selectedoption = { id: 192}
Get default selection
$scope.default = data.selectedoption;
the select tag
<select ng-model="default" ng-options="bank.label for bank in data.availableoptions track by bank.id">