I am implementing a Change Password Screen In which i need to check the equality of Password and Confirm Password . so I am implementing a custom validation.
But I am getting some exception " matcher.isErrorState is not a function".Please find my code below and let me know what is missing from my side.
TypeScript File -
export class ChangePasswordComponent implements OnInit {
password :any;
confirmPassword:any;
form :any ;
constructor(fb: FormBuilder, private authService: AuthService, private router: Router) {
this.password = new FormControl('', [Validators.required,Validators.minLength(8) , Validators.maxLength(20), Validators.pattern(new RegExp("(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])"))]);
this.confirmPassword = new FormControl('', [Validators.required, Validators.minLength(8) , Validators.maxLength(20)]);
this.form = fb.group({
password :this.password ,
confirmPassword :this.confirmPassword
});
var that = this;
this.form.controls.confirmPassword.setValidators([this.cross(this.password)]);
}
cross( p) {
console.log("in cross");
console.log(p);
return null;
}
}
Html Component File -
<form [formGroup]="form" class="example-form" >
<mat-form-field style="width: 100%">
<input matInput placeholder="Enter your password" [type]="'password'" formControlName="password" required>
<mat-error *ngIf="form.controls.password.invalid">{{validatePassword()}}</mat-error>
</mat-form-field>
<br>
<br>
<mat-form-field style="width: 100%">
<input matInput placeholder="Confirm your password" [type]="'password'" formControlName="confirmPassword" required>
<mat-error *ngIf="form.controls.confirmPassword.invalid">{{validateConfirmPassword()}}</mat-error>
</mat-form-field>
<br>
<button color="primary" (click)="changePassword()" [disabled]="!(form.controls.confirmPassword.valid || form.controls.password.valid)" mat-raised-button>Submit</button>
</form>