0
我想用按鈕更改選定選項。如果我沒有在參數中使用數據綁定,代碼將按預期工作:Angular.js - 將具有數據綁定功能的按鈕中的選定選項更改爲函數參數
ng-click="changeOptions('cat');"
如果我對參數使用數據綁定,它將不再起作用。這是不允許的?
ng-click="changeOptions('{{animals.type}}');"
下面是HTML:
<div ng-app="quickApp" ng-controller="quickController">
<select ng-model="animalList" ng-options="animals.type as animals.type for animals in animals"></select>
<button ng-repeat="animals in animals" ng-click="changeOptions('{{animals.type}}');">{{animals.type}}</button>
</div>
這裏是JS:
angular
.module('quickApp', [])
.controller('quickController', ['$scope', function($scope) {
$scope.changeOptions = function(id){
$scope.animalList = id;
};
$scope.animals = [
{'type':'cat'},
{'type':'dog'},
{'type':'bear'}
];
}]);
謝謝,您的建議幫助我達到了現在正確運行的程度。 最初令人困惑的是,在查看DOM時,都使用「字符串」和「{數據綁定}」作爲參數呈現完全相同,但獲得了不同的結果。 – sjmartin