Angular JS ng-options 默认选择对象 ID

Angular JS ng-options default selection by object ID

假设我有来自数据库的这些选项

$scope.options = [
 { id: 192, value: 'Bank 1'},
 { id: 168, value: 'Bank 2'},
 { id: 0,   value: 'Bank 3'},
];

并且这段代码可以通过选择数组位置来设置默认值

<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

如何根据对象id设置默认选择?选择 192、168 或 0。

谢谢!

尝试使用 select as 表达式

ng-options="bank.id as bank.label for bank in options"
var data = {
   availableoptions: [],
   selectedoption: {}
};

向选项添加数据

data.availableoptions.push({id: 192, label: 'Bank1'});

设置默认值selection

data.selectedoption = { id: 192}

获取默认值selection

$scope.default = data.selectedoption;

select 标签

<select ng-model="default" ng-options="bank.label for bank in data.availableoptions track by bank.id">