Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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
up vote 2 down vote accepted

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>
share|improve this answer
    
its, $scope.roles=data.roles. here roles is list of role object. – Senty Sep 3 '14 at 10:38
    
In HTML i pass selected = "someValue", but i don't pass it hard coded. i want to check if role.authority contains "SOMEROLE" then set to to default selected. – Senty Sep 3 '14 at 10:40
    
yes, so after this line you can assign $scope.user.role = $scope.roles[0].authority where 0 is your default role – maurycy Sep 3 '14 at 10:41
    
no its not like that, i want to do like ng-if(role.authority=="ROLENAME") then this is selected, and when i call this it give me selected data. this time i select role to perform action. now can i set something as default from my list after check in ng-if or something like that – Senty Sep 3 '14 at 10:48
    
I've edited my answer with ngSelected use – maurycy Sep 3 '14 at 10:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.