Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide show eye icon inside password field angular 6

Tags:

angular

The function is working fine but i'm doing it with a checkbox till now I just need help with the eye icon inside the password input field without bootstrap or font-awesome if possible and thanks

      myFunction() {
  let x : any = document.getElementById("inputPassword");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }
}

<input [(ngModel)]="password" type="password" id="inputPassword"  name="password"
                     placeholder="{{'Password' | translate}}"  required>
                     <input type = "checkbox" (click)="myFunction()">
like image 261
Kha15 Avatar asked Sep 02 '25 15:09

Kha15


1 Answers

I would do as the official were documented:

Instead of setting type in the component use dynamic value for the type attribute.

HTML:

<input placeholder="Enter your password" [type]="hide ? 'password' : 'text'">

TS Code:

hide : boolean = true;

myFunction() {
  this.hide = !this.hide;
}

Working_Demo_with_eye_icon

like image 127
Prashant Pimpale Avatar answered Sep 05 '25 16:09

Prashant Pimpale