选择& amp;有一些奇怪的问题ng-repeat ..如果我从控制器指定它,则值会被绑定,但如果我从api调用中获取它,则不会... ...
<div>Operator is: {{condition.operator}}</div>
<select ng-model="condition.operator">
<option ng-repeat="operator in operators" value="{{operator.value}}">{{operator.displayName}}</option>
</select>
为什么这种奇怪的行为?我用ng-options尝试解决了这个问题,所以我们必须使用ng-options总是选择而不是ng-repeat ??
答案 0 :(得分:0)
使用ng-options
<select ng-model="filterCondition.operator" ng-options="operator.value as operator.displayName for operator in operators">
答案 1 :(得分:0)
你可以做两种方式
第一种方法 - Working Demo
<select ng-model="condition.operator">
<option ng-repeat="operator in operators" value="{{operator.value}}">
{{operator.displayName}}
</option>
</select>
第二种方法 - Working Demo
<select ng-model="condition.operator" ng-options="operator.value as operator.displayName for operator in operators"/>