2014-09-24 4 views

답변

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") 
관련 문제