基本上我有密码和确认输入,我希望确认输入验证它是否与密码输入相同..你知道它是如何工作的。
我的问题:每次更改密码输入时,我都无法弄清楚如何更新确认验证器。我当前的代码永远不会更新它。
component.ts:
export class LoginComponent
confirmPassword = '';
newPasswordForm = new FormControl('', [
Validators.required, Validators.minLength(5), Validators.maxLength(256),
Validators.nullValidator, Validators.pattern(pwRegexp)]);
confirmPasswordForm = new FormControl('', [
Validators.required, Validators.pattern(this.confirmPassword)]);
和html:
<mat-form-field>
<input #newPassword matInput placeholder="Password" [formControl]="newPasswordForm" [type]="hide2 ? 'password' : 'text'" [(ngModel)]="meme">
<mat-icon matSuffix (click)="hide2 = !hide2">{{hide2 ? 'visibility' : 'visibility_off'}}</mat-icon>
<mat-error *ngIf="newPasswordForm.invalid">{{getNewPasswordErrorMessage()}}</mat-error>
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Confirm password" [formControl]="confirmPasswordForm" [type]="hide3 ? 'password' : 'text'">
<mat-icon matSuffix (click)="hide3 = !hide3">{{hide3 ? 'visibility' : 'visibility_off'}}</mat-icon>
<mat-error *ngIf="confirmPasswordForm.invalid">{{getConfirmPasswordErrorMessage()}}</mat-error>
</mat-form-field>