微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – md-select不能设置选定的值

我有一个md-select设置如下:
<md-select placeholder="Category" ng-model="current.Category" flex >
    <md-option ng-repeat="item in categories" ng-value="{{item}}">{{item.Name}}</md-option>
</md-select>

@ scope.categories值是

[  
{  
  "Name":"Commercial & Industrial","ParentId":null,"Categories":[  
     {  
        "Name":"Deceptive Marketing","ParentId":19,"Categories":[  

        ],"Id":24,"ModifiedDate":"2015-08-06T07:49:53.0489545","CreatedDate":"2015-08-06T15:49:51.707"
     },{  
        "Name":"Aggressive Agents","Id":25,"ModifiedDate":"2015-08-06T07:50:10.0026497","CreatedDate":"2015-08-06T15:50:08.63"
     }
  ],"Id":19,"ModifiedDate":"08/06/2015 @ 7:49AM","CreatedDate":"08/06/2015 @ 3:49PM"
 },{  
  "Name":"Competitive Supply","Categories":[  
     {  
        "Name":"Security Deposit","ParentId":20,"Id":21,"ModifiedDate":"2015-08-06T07:49:30.3966895","CreatedDate":"2015-08-06T15:49:25.8"
     },{  
        "Name":"Meter","Id":22,"ModifiedDate":"2015-08-06T07:49:34.6571155","CreatedDate":"2015-08-06T15:49:33.3"
     },{  
        "Name":"Bill","Id":23,"ModifiedDate":"2015-08-06T07:49:41.7268224","CreatedDate":"2015-08-06T15:49:40.357"
     }
  ],"Id":20,"CreatedDate":"08/06/2015 @ 3:49PM"
   }
]

md-select工作正常.但是我无法想像的是如何设置选择值.当我尝试将模型current.Category设置为$scope.categories中的一个值时,它不会设置.

文档不明确,但您应该使用ng选择.我创造了一个 codepen来说明,但基本上是:
<md-option ng-repeat="(index,item) in categories" ng-value="{{item}}"
           ng-selected="index == 1">    
    {{item.Name}}
</md-option>

这将选择第二个类别(您的类别数组中的索引1).

原文地址:https://www.jb51.cc/angularjs/143125.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐