[英]Why the angular-js ng-option not showing as selected?
<select ng-model="field.value" class="form-control" ng-attr-name="{{name}}">
<option selected="selected">{{field.fieldName}}</option>
<option ng-repeat="app in field.attributes.split(',')" value="{{app}}">{{app}}</option>
</select>
In this code, my expected behaviour is , it will show the select box and it select the first option I have added selected="selected". 在此代码中,我的预期行为是,它将显示选择框,并选择我添加的第一个选项selected =“ selected”。
but it not selecting that "selected" attribute element. 但它没有选择该“选定”属性元素。
I have tried this with ng-selected="true" also. 我也尝试了ng-selected =“ true”。 It also not help for me.
这对我也没有帮助。 any suggestion for me?
对我有什么建议吗?
You should be using the ngOptions
directive - not a ngRepeat
on an option
element: 你应该使用
ngOptions
指令-不是ngRepeat
的上option
元素:
<select ng-model="field.value" ng-options="app as app for app in field.attributes.split(',')" class="form-control" ng-attr-name="{{name}}"></select>
Now simply set your ngModel
( field.value
) to the field you want selected. 现在,只需将
ngModel
( field.value
)设置为要选择的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.