Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itswadesh/4226776ec0f29be966e864e953ebbf23 to your computer and use it in GitHub Desktop.
Save itswadesh/4226776ec0f29be966e864e953ebbf23 to your computer and use it in GitHub Desktop.
app.directive('focus', function() {
return function(scope, element) {
element[0].focus();
}
});
app.directive('passwordMatch', [function () {
return {
restrict: 'A',
scope:true,
require: 'ngModel',
link: function (scope, elem , attrs,control) {
var checker = function () {
//get the value of the first password
var e1 = scope.$eval(attrs.ngModel);
//get the value of the other password
var e2 = scope.$eval(attrs.passwordMatch);
if(e2!=null)
return e1 == e2;
};
scope.$watch(checker, function (n) {
//set the form control to valid if both
//passwords are the same, else invalid
control.$setValidity("passwordNoMatch", n);
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment