我想要選擇一個對象數組。 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