angular 禁用瀏覽器密碼
阿新 • • 發佈:2020-07-17
https://www.zhihu.com/question/23529765(方法來源)
html
<input style="display:none" type="text" class="login-password" [(ngModel)]="passwordValue" formControlName="passwordTwo"> <input nz-input type="text" formControlName="password" class="log-password" placeholder="請輸入密碼" [(ngModel)]="passwordVal" (ngModelChange)="chagePassword()">
ts
passwordVal = ''; passwordValue = ''; trueValue = [];//儲存真實資料的陣列 beforeLength = 0;//隱藏框value的長度 chagePassword() { let nowLength = this.passwordVal.length;// 變化後的長度 if (nowLength > this.beforeLength) {//長度增加時 this.trueValue.push(this.passwordVal[nowLength - 1]);++this.beforeLength; } else {//長度減少時 this.trueValue.pop(); --this.beforeLength; } this.passwordValue = this.trueValue.join(''); let nowValue = '';//轉換為圓點 for(let i = 0; i < nowLength; ++i){ nowValue += '•'; }if(nowValue){ this.eleRef.nativeElement.querySelector('.log-password').value = nowValue; } }