Shift 'n Tab
Shift 'n Tab

Reputation: 9443

How to programmatically set a value to md-select

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

Upvotes: 1

Views: 579

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

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

Upvotes: 1

Related Questions