Why select tag with ng-options works correctly by showing the default selected value but same is not working if I use with ng-repeat.
here is the code,
NullPointerException
in app.js,
<!-- this works-->
<select class="form-control" ng-model="selectValue" ng-options="option.id as option.name for option in availableOptions">
</select>
<!-- this also works-->
<select ng-model="selectValue">
<option ng-repeat="options in availableOptions" value="{{options.id}}" ng-selected="selectValue === options.id">{{options.name}}</option>
</select>
<!-- this doesnt works-->
<select ng-model="selectValue">
<option ng-repeat="options in availableOptions" ng-value="options.id" ng-selected="selectValue === options.id">{{options.name}}</option>
</select>
Though the HTML shows the selected attribute, still its not rendered properly in the view
Here is the plunker link for the same
答案 0 :(得分:0)
虽然在网页上下拉的正确方法应该是使用ng-options
,但您可以更改下面的标记,以使其与ng-repeat
版本一起使用。
<强>标记强>
<select ng-model="selectValue">
<option ng-repeat="options in availableOptions" value="{{options.id}}">
{{options.name}}
</option>
</select>