Neel
Neel

Reputation: 21243

how to change input type in angularjs

I have 2 fields one is password and another is checkbox

...
...
<input type="password" ng-model="data.password" id="form_password"></input>
<input type="checkbox" ng-model="data.show_password" id="show_password"></input>
<label> Show Password</label>
...
...

When user click on show_password checkbox, I want to change form_password type to text so user can see the password.

Upvotes: 0

Views: 59

Answers (1)

jdotjdot
jdotjdot

Reputation: 17052

I would do the following:

<input ng-show="!data.show_password" type="password" ng-model="data.password" id="form_password">
<input ng-show="data.show_password" type="text" ng-model="data.password">
<input type="checkbox" ng-model="data.show_password" id="show_password">
<label>Show Password</label>

(or obviously you could use ng-hide, stylistic preference)

Upvotes: 4

Related Questions