Skip to content

Instantly share code, notes, and snippets.

@parollon
Last active October 1, 2024 10:35
Show Gist options
  • Select an option

  • Save parollon/e37ea40a613146445d9f6546b50e29ad to your computer and use it in GitHub Desktop.

Select an option

Save parollon/e37ea40a613146445d9f6546b50e29ad to your computer and use it in GitHub Desktop.
show hide password fuction many
<ion-input
[type]="getPasswordStatus('password1')"
>
<ion-button
(click)="showHidePassword('password1')"
fill="clear"
slot="end"
aria-label=""
>
<ion-icon
[name]="getPasswordIcon('password1')"
slot="icon-only"
></ion-icon>
</ion-button>
</ion-input>
interface IPasswordStatus {
name: string;
type: string;
icon: string;
}
passwordStatus:IPasswordStatus[] = [
{
name: 'password1',
type: 'password',
icon: 'eye-outline',
},
{
name: 'password2',
type: 'password',
icon: 'eye-outline',
},
];
getPasswordStatus(inputName: string) {
const status = this.passwordStatus.find((t) => t.name === inputName);
return status ? status.type : 'password';
}
getPasswordIcon(inputName: string) {
const status = this.passwordStatus.find((t) => t.name === inputName);
return status ? status.icon : 'eye-outline';
}
showHidePassword(inputName: string) {
const status = this.passwordStatus.find((status) => status.name === inputName);
if (status) {
status.type = status.type === 'password' ? 'text' : 'password';
status.icon = status.icon === 'eye-outline' ? 'eye-off-outline' : 'eye-outline';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment