这是我的下拉列表:
<select class="form-control form-controls input-sm" ng-model="vm.retailer.state" ng-options="state.code as state.name for state in vm.states" required>
<option value="">-- Select a State --</option>
</select>
这里只是数据中的第一个状态:
"State": [
{
"code": "AL",
"name": "Alabama"
},
以下是在HTML中呈现的内容:
<select class="form-control form-controls input-sm ng-pristine ng-invalid ng-invalid-required ng-touched" ng-model="vm.retailer.state" ng-options="state.code as state.name for state in vm.states" required="">
<option value="" class="">-- Select a State --</option>
<option value="0" label="Alabama">Alabama</option>
...
</select>
我一直在寻找其他提出同样问题的帖子,或多或少,但没有任何效果。我在加载状态的方法上设置了一个断点,我可以确认Code和Name都在发送到视图的数组中。
答案 0 :(得分:0)
终于找到了一个有正确答案的帖子。我失踪了#34;跟踪state.code&#34;。这就行了。
<select class="form-control form-controls input-sm" ng-model="vm.retailer.state" ng-options="state.code as state.name for state in vm.states track by state.code" required>
<option value="">-- Select a State --</option>
</select>