window.angular && (function(angular) { 'use strict'; /** * Password visibility toggle * * This attribute directive will toggle an input type * from password/text to show/hide the value of a password * input field. * * To use: * */ angular.module('app.common.directives') .directive('passwordVisibilityToggle', [ '$compile', function($compile) { return { restrict: 'A', link: function(scope, element) { const instanceScope = scope.$new(); const buttonTemplate = ` `; instanceScope.visible = false; instanceScope.toggleField = () => { instanceScope.visible = !instanceScope.visible; const type = instanceScope.visible ? 'text' : 'password'; element.attr('type', type); }; element.after($compile(buttonTemplate)(instanceScope)); } }; } ]); })(window.angular);