이것은 정규식으로 간단한 검증을 수행하는 지시어입니다. 어떤 이유로 나는 지시문 바깥에있는 체크 박스 값을 전달하는 문제가있다. 나는 checkEmailOnBlur라는 내 지시에 scope.validationEnabled라고 체크 박스 값을 읽기 위해 노력하고 있어요 :범위 체크 박스 값이 지시어에 전달되지 않았습니까?
app.directive('checkEmailOnBlur', function() {
var ABN_REGX = /^(\d *?){3}$/;
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attr, ctrl) {
if (scope.validationEnabled) {
if (attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input').unbind('keydown').unbind('change');
elm.bind('blur', function() {
scope.$apply(function() {
if (ABN_REGX.test(elm.val())) {
ctrl.$setValidity('abns', true);
console.log('valid abn');
scope.acn = "1010101";
scope.displayName = "display name";
scope.otherName = "otherName";
scope.description = "desc";
} else {
ctrl.$setValidity('abns', false);
console.log('not valid abn');
scope.acn = "";
scope.displayName = "";
scope.otherName = "";
scope.description = ""
}
});
});
}
}
};
질문 :이 확인란을 선택하면 순간에 scope.validationEnabled에 대한 TRUE로 설정되어 있지 않습니다. 체크 박스 값을 어떻게 전달할 수 있습니까? 링크 기능을 실행하면 http://plnkr.co/edit/O69SP2sB5NZcPirImhrh?p=preview가