-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathangular-password.js
More file actions
54 lines (43 loc) · 1.56 KB
/
angular-password.js
File metadata and controls
54 lines (43 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function() {
'use strict';
function $Password() {
function link(scope, element, attrs, ctrls) {
var formController = ctrls[1];
var ngModel = ctrls[0];
var otherPasswordModel = formController[attrs.matchPassword];
var getMatchValue = function() {
return otherPasswordModel.$viewValue;
};
scope.$watch(getMatchValue, function() {
ngModel.$$parseAndValidate();
});
// if ng1.3+
if (ngModel.$validators) {
ngModel.$validators.passwordMatch = function(modelValue) {
return (!modelValue && !otherPasswordModel.$modelValue) || (modelValue === otherPasswordModel.$modelValue);
};
} else {
ngModel.$parsers.push(function(value) {
ngModel.$setValidity('passwordMatch', (!value && !otherPasswordModel.$viewValue) || value === otherPasswordModel.$viewValue);
return value;
});
}
otherPasswordModel.$parsers.push(function(value) {
ngModel.$setValidity('passwordMatch', (!value && !ngModel.$viewValue) || value === ngModel.$viewValue);
return value;
});
}
var controllers = ['^ngModel', '^form'];
return {
restrict: 'A',
require: controllers,
link: link
}; // end return
}
angular.module('ngPassword', []).directive('matchPassword', $Password);
angular.module('angular.password', ['ngPassword']);
angular.module('angular-password', ['ngPassword']);
if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngPassword');
}
})();