0
확인란이 있으며 선택하면 연결된 텍스트 상자가 비어 있어서는 안됩니다. 이 사례에 지침을 사용해야합니까, 아니면 더 좋은 방법이 있습니까?각도로 종속 텍스트 상자의 유효성을 검사하는 방법
확인란이 있으며 선택하면 연결된 텍스트 상자가 비어 있어서는 안됩니다. 이 사례에 지침을 사용해야합니까, 아니면 더 좋은 방법이 있습니까?각도로 종속 텍스트 상자의 유효성을 검사하는 방법
예. 지침을 사용해야합니다.
일치하는 필드에 $watch
을 설정하여 변경중인 다른 필드가 일치하는지 확인하고 현재 필드의 업데이트가 다른 필드와 일치하는지 확인하는 구문 분석기를 추가해야합니다.
ngModelController
에 연결하면 모든 inbuilt 유효성 검사 기능을 활용할 수 있습니다. 이 (커피 스크립트) 같은
뭔가 :
.directive('pxnMatchField', ($parse)->
restrict: 'A'
require: '?ngModel'
link: (scope, elem, attrs, ngModel)->
if !ngModel
return console.warn "no model specified on match field element"
scope.$watch("#{attrs.pxnMatchField}", (newVal)->
ngModel.$setValidity('pxnMatchField', (newVal is ngModel.$viewValue))
)
# Dom input validation
ngModel.$parsers.push((domVal)->
ngModel.$setValidity('pxnMatchField',
(domVal is $parse(attrs.pxnMatchField)(scope)))
return domVal
)
)
이 다음 마크 업 함께 작동 (옥) :
label Password
input(ng-model="password")
label Confirm Password
input(ng-model="confirmPassword", pxn-match-field="password")