[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] Checkbox篩選元素作法留存 (配reactive form)

[Telegram Bot] 開發回聲機器人程式碼暫存

[Angular Material] 搜尋式下拉選單範例