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 badges1 Answer
Reset to default 5You 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>