我有一个提交验证按钮,需要在正确输入所有字段时启用。由于验证过于复杂,无法单独使用formName。$ invalid来解决,因此我需要编写一个函数来满足验证要求。我希望应该为每个模型更改内部触发shouldEnable函数。但事实并非如此。操作系统对此有其他选择吗?
初始
<button ng-disabled="formName.$invalid">Submit</button>
预期
<button ng-disabled="shouldEnable()">Submit</button>
$scope.shouldEnable = function() {
$scope.isEnable = true;
angular.forEach($scope.form.input2, function(val) {
if($scope.form.input2.inputA && $scope.form.input2.inputB) {
isEnable = false;
}
})
}
最佳答案
您的函数需要返回 bool(boolean) 值:
$scope.shouldEnable = function() {
var isEnable = true;
// make necessary checks
return isEnable;
}