简体   繁体   English

md-select不更新模型

[英]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 : 但是在我的upadateView()中,当我记录userSelected时,我总是得到这个我选择的:

Object {$$mdSelectId: 1}

I initialise it in my controller like this 我在我的控制器中初始化它

$scope.personneSelected = {};

Did I miss something ? 我错过了什么 ?

在此输入图像描述

我通过使用ng-show而不是ng-if解决了我的问题。

You should initialise the ng-model variable with one of the default values that appears in the users collection to get it right. 您应该使用users集合中显示的一个默认值初始化ng-model变量,以使其正确。

Refer to the post https://stackoverflow.com/a/12654812/1196544 请参阅帖子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. 此外,无论返回什么,都应该是'用户'的对象,因为angularJS将对象本身存储为select的每个选项的值。

Use console.dir() instead of console.log() to view the object properties (in chrome). 使用console.dir()而不是console.log()来查看对象属性(在chrome中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM