angularjs select标签使用ng-repeat标签之后,ng-model无法更新问题,百度了一下没有发现原因,后来采用了jquery的方式进行首次赋值,如下过程:
我也遇到过这样的问题,由于option是使用ng-repeat生成的,ng-model首次并没有更新,后来采用了jquery的方式,给select设置一个id,然后使用jquery的方式赋值,如下:
html代码:
<select ng-model="upName" id="up_name" >
<option value="">无</option>
<option ng-repeat="familyName in familyNames track by $index" value={{familyName}}">{{familyName}}</option>
</select>
js代码: setTimeout(function () {
$("#up_name").val($scope.upName);
}, 200);
这里有一个必须延迟一下才能赋值成功,我猜测是因为ng-repeat执行在后面,导致ng-model无法更新,有知道的前辈可以告诉我怎么处理