Alexandre
Alexandre

Reputation: 588

md-select doesn't update model

I have this following code :

<md-select ng-change="updateView()" 
           ng-model="userSelected" 
           ng-if="authuser.privilege >= 3">
    <md-option ng-repeat="user in users" 
               ng-value="user">{{user.name}}</md-option>
</md-select>

But in my upadateView() when I log the userSelected I always get this whatever I choose :

Object {$$mdSelectId: 1}

I initialise it in my controller like this

$scope.personneSelected = {};

Did I miss something ?

enter image description here

Upvotes: 4

Views: 2704

Answers (2)

Alexandre
Alexandre

Reputation: 588

I solved my problem by using ng-show instead of the ng-if.

Upvotes: 11

urpalreloaded
urpalreloaded

Reputation: 506

You should initialise the ng-model variable with one of the default values that appears in the users collection to get it right.

Refer to the post https://stackoverflow.com/a/12654812/1196544

Also, whatever that's been returned should have been an object of 'user' since angularJS stores the object itself as the value of every option for the select.

Use console.dir() instead of console.log() to view the object properties (in chrome).

Upvotes: 2

Related Questions