最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ng-Select Option set default value from list if value match using angularJS - Stack Overflow

programmeradmin0浏览0评论

I have 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>

Now roles is a list and role.authority is string. i want to set default selected if role.authority==MYROLE then set to default, which is in role.authority.

How can i do

I have 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>

Now roles is a list and role.authority is string. i want to set default selected if role.authority==MYROLE then set to default, which is in role.authority.

How can i do

Share Improve this question edited Oct 11, 2014 at 8:19 Santosh asked Sep 3, 2014 at 10:11 SantoshSantosh 551 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You have to assign the same value to select model inside controller, in your case it would be something like this

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

or with use of ngSelected

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

评论列表(0)

  1. 暂无评论