[Angular Material] 輸入密碼可以切換檢視和不檢視




HTML

  <mat-form-field>
            <input
              matInput
              placeholder="密碼"
              [type]="isPasswordHide ? 'password' : 'text'"
              autocomplete="on"
              formControlName="accountPassword"
            />
            <button
              mat-icon-button
              matSuffix
              (click)="isPasswordHide = !isPasswordHide"
              [attr.aria-label]="'Hide password'"
              [attr.aria-pressed]="isPasswordHide"
            >
              <mat-icon>{{
                isPasswordHide ? 'visibility_off' : 'visibility'
              }}</mat-icon>
            </button>
          </mat-form-field>




TS

  // 設置輸入密碼時可否看到的值
  isPasswordHide = true;





















留言

這個網誌中的熱門文章

[Angular] 閒置登出作法

[Angular] 回到最上面 goTop按鈕作法

[SQL] 如何快速搜尋整個 SQL Server 資料庫中所有表格所有欄位中的所有資料