Santosh
Santosh

Reputation: 55

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

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

Upvotes: 1

Views: 6026

Answers (1)

maurycy
maurycy

Reputation: 8465

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>

Upvotes: 5

Related Questions