我可以在angularjs中使用默认值设置一个下拉列表,
<select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init=" repeatSelect = data[0].id"> <option ng-repeat="option in data" value="{{option.id}}">{{option.name}}</option> </select>
如何使用来达到相同的效果ng-options?我胆战心惊,
ng-options
<select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init=" repeatSelect = option.id" ng-options="option.name for option in data track by option.id"> </select>
但是没用。样品小提琴在这里
使用ng-init 为设定的默认值ng-options。
ng-init
这是: 演示
<select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init=" repeatSelect = data[0].id" ng-options="option.id as option.name for option in data"> </select>