【发布时间】:2016-04-26 05:43:15
【问题描述】:
我想选择对象数组。example 但不知何故,我无法访问所选对象的属性。
js---
$scope.test1={};
$scope.test = [{'name':'test1'},{'name':'test2'},{'name':'test3'}];
html--
<select style="width:100px;height:25px;" ng-model="test1">
<option ng-repeat="attribute in test" value="{{attribute}}">{{attribute['name']}}</option>
</select>
{{test1}}
{{test1.name}}
这里,test1.name 为空白。
【问题讨论】:
-
在这种情况下您应该使用
ng-options而不是ng-repeat。option标签只能绑定到字符串,所以你的test1在这种情况下不是一个对象,它实际上是对象的字符串表示。ng-options旨在克服这种行为。
标签: html angularjs select angularjs-ng-model