1window.angular && (function(angular) { 2 'use strict'; 3 4 /** 5 * Password confirmation validator 6 * 7 * To use, add attribute directive to password confirmation input field 8 * Also include attribute 'first-password' with value set to first password 9 * to check against 10 * 11 * <input password-confirmation first-password="ctrl.password" 12 * name="passwordConfirm"> 13 * 14 */ 15 angular.module('app.common.directives') 16 .directive('passwordConfirm', function() { 17 return { 18 restrict: 'A', 19 require: 'ngModel', 20 scope: {firstPassword: '='}, 21 link: function(scope, element, attrs, controller) { 22 if (controller === undefined) { 23 return; 24 } 25 controller.$validators.passwordConfirm = 26 (modelValue, viewValue) => { 27 const firstPassword = 28 scope.firstPassword ? scope.firstPassword : ''; 29 const secondPassword = modelValue || viewValue || ''; 30 if (firstPassword == secondPassword) { 31 return true; 32 } else { 33 return false; 34 } 35 }; 36 element.on('keyup', () => { 37 controller.$validate(); 38 }); 39 } 40 }; 41 }); 42})(window.angular); 43