2015-01-22 8 views
0

각도를 사용하여 간단한 비밀번호 유효성 검사를 통합하려고합니다. 어떤 이유로 든 ngModel. $ validate()가 정의되지 않아 실제로 유효성 검사가 수행되지 않습니다. 어떤 도움이 크게 appericated입니다. 내가 라우터있어

angular.module('todo') 
    .controller('RegisterController', ['$scope', '$http', '$location', function($scope, $http, $location) { 
     $scope.register = function() { 
    }); 

: 나는 사용자 정의 컨트롤러있어

.config(function($routeProvider) { 
    $routeProvider. 
     when('/todo', { 
      templateUrl: './partials/todo.html', 
      controller: 'TodoController' 
     }). 
     when('/register', { 
      templateUrl: './partials/register.html', 
      controller: 'RegisterController' 
     }). 
     otherwise({ 
      redirectTo: '/todo' 
     }); 
}); 

을 그리고 나는 지시어있어 :

var compareTo = function() { 
    return { 
     require: "ngModel", 
     scope: { 
      otherModelValue: "=compareTo" 
     }, 
     link: function(scope, element, attributes, ngModel) { 
      ngModel.$validators.compareTo = function(modelValue) { 
       return modelValue == scope.otherModelValue; 
      }; 

      scope.$watch("otherModelValue", function() { 
       console.log('in otherModelValue '); 
       console.log('ngModel.$validate() : ' + ngModel.$validate()); 
       ngModel.$validate(); 
      }); 
     } 
    }; 
}; 
angular.module('todo').directive("compareTo", compareTo); 

내가 모두 함께 결합을 다음 방식으로 :

<input id="password" name="password" type="password" placeholder="Password" ng-model="password" required/> <br/> 
    <input id="passwordConfirm" type="password" placeholder="Repeat Password" ng-model="confirmPassword" required compare-to="password" /> <br/> 
+1

내가/믿는 confirmPassword 필드에 confirmPasswordname 속성을 추가하면 실제로보고 있다고 생각하는 ngModel $를 확인합니다. - 반환 값이 아닌 함수가 정의되지 않았습니다. 해결책을 찾았습니까? –

+0

어떻게이 문제를 해결 했습니까? – Ankita

답변

0

ngModel.$validate()은 특정 값을 반환하지 않으므로 의도적으로 정의되지 않아야합니다. 유효성 검사가 작동하지 않지만 유효성 검사를 표시 할 방법이 없습니까? 템플릿에 추가하십시오 (양식을 가정하는 것은 name="form"있다) :

또한

<span ng-show="form.confirmPassword.$error.compareTo">Passwords must match</span>

관련 문제