我有一个这样的自定义验证:
app.directive('checkRfc', function() {
return {
require: 'ngModel',
link: function(scope, element, attr, mCtrl) {
function checkRfcValidation(value) {
if (scope.clientForm.requireBill.$modelValue === "1" && value.length > 0) {
mCtrl.$setValidity('rfcOk', true);
//scope.examsForm.authorization.$setValidity("discountOk", true);
}
else {
mCtrl.$setValidity('rfcOk', false);
//scope.examsForm.authorization.$setValidity("discountOk", false);
}
return value;
}
mCtrl.$parsers.push(checkRfcValidation);
}
};
});
工作正常,但我必须在相应的字段中输入一些字符,然后才会触发验证。有没有办法在表单加载时自动激活验证?