有什么方法可以执行非严格比较<select>
ngOptions
以便从模型中设置初始值?例如,如果模型是整数并且选项键属性是字符串值,那么<select>
很遗憾没有设置初始值。
HTML:
<div ng-app="app">
<div ng-controller="Controller">
<select data-ng-model="model" data-ng-options="option.id as option.text for option in options"></select>
</div>
</div>
JS:
var app = angular.module('app', []);
app.controller('Controller', function ($scope) {
$scope.model = '2'; // This works as an integer (2) but not as a string ('2')
$scope.options = [
{id: 1, text: '11111'},
{id: 2, text: '22222'}, // I want this option to be selected
{id: 3, text: '33333'}
];
});