Angular JS ng-model对<select>标签无效的情况

使用场景一:

<select ng-if="item.award_type==1" id="award{{$index+1}}" name="XXXXX[award{{$index+1}}]" ng-model="item.award">
      <option ng-repeat="(key, value) in List track by $index" value="{{key}}">{{value}}</option>
</select>

使用场景二:

<select id="award_type{{$index+1}}" name="XXXXX[award_type{{$index+1}}]" ng-model="item.award_type" ng-change="changeAwardType($index)">
       <option value="0">请选择奖品</option>
       <option value="1">商品券</option>
       <option value="2">优惠券</option>
       <option value="3">实物奖励</option>
</select>

<select> - <option> 配合 ng-model 使用的话

如果是场景二, ng-model 绑定数据后,下面的 <option> 能随 ng-model 绑定的数据改变,即将对应value的<option>设为selected;

如果是场景一,<option> 使用 ng-repeat 绑定数据,<select>用 ng-model 绑定则无法起到将对应的<option>设为selected,此时代码得做相应的修改,使用ng-selected进行处理

<select ng-if="item.award_type==1" id="award{{$index+1}}" name="XXXXX[award{{$index+1}}]" ng-model="item.award">
      <option ng-repeat="(key, value) in List track by $index" value="{{key}}" ng-selected="item.award==key?'selected':''">{{value}}</option>
</select>
原文地址:https://www.cnblogs.com/lyc94620/p/9728745.html