如何设置ng-selected为true?

时间:2018-06-20 10:00:24

标签: html angularjs

我必须显示在下拉列表中选择的用户名。

 <select name="field_user" id="field_user"  class="txt_box sel_box" ng-model="field_user_select" >
<option value="" disabled selected>Select Field User</option>
<option ng-repeat="user in field_user_list" value="{{user._id}}" ng-selected="current_user._id">{{user.owner_name}}</option>
</select>

该怎么做?

1 个答案:

答案 0 :(得分:0)

NgSelected等待一个表达式。如果为true,则会将selected属性放入选项。因此,您需要执行以下操作:

<option ng-repeat="user in field_user_list" value="{{user._id}}" ng-selected="user._id === current_user._id">{{user.owner_name}}</option>