ngOptions与ngModel的非严格比较

时间:2018-04-21 19:07:12

标签: javascript angularjs ng-options angularjs-ng-options angularjs-select

有没有办法在print("This is a random message") print("This is another message") print("This is getting boring") <select>中执行非严格比较,以便从模型中设置初始值?例如,如果模型是整数且options键属性是字符串值,则遗憾的是ngOptions初始值未设置。

HTML:

<select>

JS:

<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>

1 个答案:

答案 0 :(得分:0)

如果我没弄错,您需要在ng-options中添加“track by”关键字,例如:

    <select data-ng-model="model" data-ng-options="option.id as option.text for option in options track by option.id"></select>