javascript - password check directive elem.add error -
i'm making password checking directive ensure password , confirm_password fields same:
angular .module('mymodule') .directive('pwcheck', function() { return { require: 'ngmodel', link: function (scope, elem, attrs, ctrl) { var password = "#" + attrs.pwcheck; elem.add(password).on('keyup', function() { scope.$apply(function () { ctrl.$setvalidity('pwmatch', elem.val() === $(password).val()); }); }); } }; });
i error when adding keyup
handler both pw , pw check fields:
typeerror: elem.add not function
so removed .add()
,
elem.on('keyup', function() {
now i'm getting following error:
referenceerror: $ not defined
i'm following this codepen. i've set angular app correctly, , directive logs html elements (elem, attrs, ctrl) fine. i'm not sure problem is.
your jquery
missing. suggest use scope
variable inside directive have access scope of controller directive, because not creating isolated scope.
code
angular.module('mymodule') .directive('pwcheck', function() { return { require: 'ngmodel', link: function (scope, elem, attrs, ctrl) { var password = "#" + attrs.pwcheck; elem.add(password).on('keyup', function() { scope.$apply(function () { ctrl.$setvalidity('pwmatch', elem.val() === scope[attrs.pwcheck]); }); }); } }; });
Comments
Post a Comment