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/>
내가/믿는 confirmPassword 필드에
confirmPassword
의name
속성을 추가하면 실제로보고 있다고 생각하는 ngModel $를 확인합니다. - 반환 값이 아닌 함수가 정의되지 않았습니다. 해결책을 찾았습니까? –어떻게이 문제를 해결 했습니까? – Ankita