我想要选择一个对象数组。 example但不知何故,我无法访问所选对象的属性。Angularjs为对象选择ng-model绑定
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'旨在克服这种行为。 – Claies