我正在尝试保留我的提交按钮disabled
,直到表单为HTML有效,我已设法这样做:
<button type="submit" class="btn" ng-disabled="mainPaymentForm" ng-click="disableButton()"><%button%></button>
在我的控制器中我有这个:
// Disable form on submit
$scope.disableButton = function(){
$scope.button = "Loading...";
$scope.submit.disable = true; // This doesn't work
};
总的来说,我只是试图保持按钮被禁用直到有效/并且一旦有效就阻止多次提交点击。
由于
答案 0 :(得分:1)
我明白了:
HTML代码
ng-disabled="mainPaymentForm.$invalid || clickDisable"
JS控制器代码
// this will unable button if form becomes valid
$scope.$watch('mainPaymentForm.$invalid', function(){
$scope.clickDisable = false;
});
// this will disable it on click
$scope.disableButton = function(){
$scope.button = "Loading...";
$scope.clickDisable = true;
};