angularjs - Change input type using directives by checkbox click -
my main goal change input type of password text cliking checkbox.
understanding dom manipulations should done in directive , after reading angularjs: can't change input type
i stared directive follows ( code included in jsfiddle )
<div ng-app="signcomponents"> <bca-sign-up-password> </bca-sign-up-password> </div>
however did not make work yet . . . suggestions? working out in angular way?
thanks!
first off, element.html
method not property, yo overwriting function inside of scope.$watch
callback. second, it's easier on (yourself, angular, browser) change input type:
scope.$watch('viewpasswordcheckbox', function (newvalue) { element.find('input')[1].type = newvalue ? 'password' : 'text'; });
edit: if need support older versions of ie (the above works in 9), can render input twice , show/hide this: http://jsfiddle.net/k6qgm/7/
function (newvalue) { var show = newvalue ? 2 : 1, hide = newvalue ? 1 : 2, elements = element.find('input'); elements[hide].style.display = 'none'; elements[show].style.display = ''; });
Comments
Post a Comment