I have this form and validation function in the .ts :
ngOnInit(): void {
this.form = this.formBuilder.group(
{
email: ['', [Validators.required, Validators.email]],
password: [
'',
[
Validators.required,
Validators.minLength(6),
Validators.maxLength(40),
this.checkPasswords.bind(this)
]
],
rePass: ['', [Validators.required, this.checkPasswords.bind(this)]],
roles: ['', [Validators.required]],
},
);
}
get f(): { [key: string]: AbstractControl } {
return this.form.controls;
}
checkPasswords(): ValidatorFn {
let pass = this.form?.value.password;
let confirmPass = this.form?.value.rePass;
return (control: AbstractControl): ValidationErrors | null => {
return( pass === confirmPass) ? null : {notSame: control.value};
}
}
And this is in my HTML:
<mat-error *ngIf="f.rePass.errors?.notSame">Error</mat-error>
So the validation function is updating correctly but it is not firing a signal to the HTML template. What am I doing wrong?