我试图绑定这两个按钮的值 - "是"和"否" - 使用formData
点击ng-model
但没有运气。除了使用ng-model
之外,有没有办法实现这个目标?
<button class=""
ng-class="{'button--is-selected--turquoise': isSelected,
'' : isSelected===false}"
ng-click="isSelected = true"
ng-model="formData.yesPool">Yes
</button>
<button class=""
ng-class="{'button--is-selected--turquoise':
isSelected === false, 'notSelected' : isSelected }"
ng-click="isSelected = false"
ng-model="formData.noPool"">No
</button>
这是我的控制人员:
angular
.module('testApp')
.controller('formController', ['$scope', '$http', function($scope, $http) {
$scope.formData = {};
$scope.processForm = function(){
};
}]);
答案 0 :(得分:5)
<script type="text/javascript">
var list = <%-JSON.stringify(events)%>;
</script>
仅适用于接受用户输入的元素,不包括按钮。如果要在单击按钮时设置值,可以将其放在ng-model
:
ng-click
或者将它们放在函数中
<button class=""
ng-class="{'button--is-selected--turquoise': isSelected,
'' : isSelected===false}"
ng-click="isSelected = true; formData.yesPool = true">Yes
</button>
<button class=""
ng-class="{'button--is-selected--turquoise':
isSelected === false, 'notSelected' : isSelected }"
ng-click="isSelected = false; formData.noPool = true">No
</button>
希望有所帮助