Setting selected item in angular md-select with multiple option
<md-select multiple ng-model="Reg.roles" placeholder="Please select roles" required>
<md-option ng-repeat="role in roles" value="{{role.value}}" ng-selected="{{ role.value === '<%= data.roles %>' ? 'true' : 'false' }}">{{ role.name }}</md-option>
</md-select>
in my controller
$scope.roles = [{
"name": "Account Admin",
"value": "account_admin"
}, {
"name": "Developer",
"value": "developer"
},
{
"name": "Analyst",
"value": "analyst"
}
];
in view
data.roles contains value:
['account_admin', 'developer']
I need the item corresponding to role.value should be in selected state.
I dunno how valid this is or if this tackles the same problem but another thing that you could do is that in your HTML, pass in role instead of role.value. So it would look something like this:
This allows you to work with the entire object in your controller and you can manipulate it as you wish.
Finally i found the solution, in my controller i wrote this: