簡體   English   中英

ng-Select Option如果使用angularJS匹配值,則從列表中設置默認值

[英]ng-Select Option set default value from list if value match using angularJS

我有HTML。

<select  ng-model="user.role" class="form-control" name="role" >
    <option value="">Select Role</option><option ng-repeat="role in roles" value="{{role.authority}}">{{role.authority}}</option> </select>

現在角色是一個列表,而role.authority是字符串。 我想設置默認值,如果role.authority == MYROLE然后設置為default,則在role.authority中。

我能怎么做

您必須分配相同的值以select控制器內的模型,在這種情況下,會像這樣

$scope.user.role = $scope.roles[0].authority

或使用ngSelected

<option ng-repeat="role in roles" value="{{role.authority}}" ng-selected="role.authority == 'defaultValue'">{{role.authority}}</option>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM