4

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

Alexandre
  • 604
  • 5
  • 21

2 Answers2

11

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

Alexandre
  • 604
  • 5
  • 21
  • 1
    Thank you. I was wondering why my custom directive (including an md-select) was not updating the model. An enclosing div was using ng-if and that was the problem. – James Bell Aug 29 '16 at 15:53
2

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

Community
  • 1
  • 1
urpalreloaded
  • 468
  • 3
  • 13