How to programmatically set a value to md-select

582 Views Asked by At

Im following this doc for md-select initial value setting. But i would like to set the value of md-select programmatically through buttons.

Here is what ive'd done so far DEMO

1

There are 1 best solutions below

1
On BEST ANSWER

md-select is expecting object value to be there in selectedUser, where as filter does return array of filtered object. You should be assigning 1st element of filtered array by doing [0] of filtered result.

$scope.selectedUser = $scope.users.filter(function(user) {
     return user.id == id;
})[0];

Forked Codepen