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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/angularjs/143125.html

猜你在找的Angularjs相关文章