猿问

angular select ng-repeat 默认选中某一项

后台请求的数据,使用如下代码


<select class="form-control" ng-model="data.pro">

        <option ng-repeat="a in pro" value="{{$index}}">

                                    {{a}}

         </option>

</select>

如何指定默认选中的某一项呢


慕田峪4524236
浏览 369回答 1
1回答

达令说

<select class="form-control" ng-model="data.model">&nbsp; &nbsp; &nbsp; <option ng-repeat="a in pro" value="{{$index}}">{{a}}</option>&nbsp; &nbsp; </select>$scope.data = {&nbsp; &nbsp; modal : "0"};modal的值就是被选中的数组下标,注意要是字符串,如果modal值是数值不会被选中。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答