You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular Material密码输入框显示双眼睛图标,如何仅显示一个?

Angular 15迁移:密码输入框出现双眼睛图标问题解决办法

在迁移至Angular 15的过程中,遇到密码输入框首次输入内容时显示两个眼睛图标的问题——一个是自定义的Material图标,另一个是浏览器自带的密码切换按钮。

相关代码

HTML模板:

<mat-form-field appearance="fill">
  <mat-label>Password</mat-label>
  <input matInput [type]="showPassword ? 'text' : 'password'" name="password">
  <mat-icon matSuffix (click)="togglePasswordVisibility()">
    {{showPassword?'visibility_off':'visibility'}}
  </mat-icon>
</mat-form-field>

TypeScript组件代码:

...
public showPassword: boolean = false;
public togglePasswordVisibility(): void {
  this.showPassword = !this.showPassword;
}
...

解决办法

通过添加CSS规则,隐藏IE/Edge浏览器自带的密码显示/清除按钮即可解决:

input[type=password]::-ms-reveal,
input[type=password]::-ms-clear
{
  display: none;
}

内容的提问来源于stack exchange,提问作者Eric Reboisson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 20:03:20