You can use the Angular user interface, it has a directive ui-validate:
<input name="password" required ng-model="password">
<input name="confirm_password" ui-validate=" '$value==password' " ui-validate-watch=" 'password' ">
Or you can create your own directive for this
myApp.directive('matchPassword', function () {
return {
require: 'ngModel',
restrict: 'A',
scope: {
matchPassword: '='
},
link: function (scope, elem, attrs, ctrl) {
scope.$watch(function () {
return (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || scope.matchSenha === ctrl.$modelValue;
}, function (currentValue) {
ctrl.$setValidity('matchPassword', currentValue);
});
}
};
});
and use it like this:
<input required name="passwordConfirm" match-password="model.Password" />
source
share