Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 767
Alexandre Avatar asked Dec 11 '22 19:12

Alexandre


2 Answers

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

like image 124
Alexandre Avatar answered Dec 24 '22 17:12

Alexandre


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).

like image 45
urpalreloaded Avatar answered Dec 24 '22 19:12

urpalreloaded