Skip to content

Instantly share code, notes, and snippets.

@ThomasHambach
Created May 12, 2016 09:24
Show Gist options
  • Save ThomasHambach/28e1adc6c5426f1b6b90ec663e93cc8b to your computer and use it in GitHub Desktop.
Save ThomasHambach/28e1adc6c5426f1b6b90ec663e93cc8b to your computer and use it in GitHub Desktop.
Angular 1.x Show Password Form Field Directive
<input type="password" show-password="">
'use strict';
function showPassword() {
return {
scope: null,
restrict: 'A',
link: function (scope, element) {
var button = angular.element('<button class="show-password">Show</button>').on('click', () => {
button.remove();
angular.element(element).attr('type', 'text');
});
angular.element(element).parent().append(button);
}
};
}
angular.module('showPassword', [])
.directive('showPassword', showPassword);
// Extending bootstrap. Style as you please.
button.show-password {
@extend .btn;
@extend .btn-link;
@extend .btn-sm;
position: absolute;
right: 0.5rem;
top: 2.45rem;
font-size: 0.6rem;
text-transform: uppercase;
padding: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment