one is password and the other one is account number, both of them have each input extra as confirm password and confirm account number. I have used reactive forms and is as follows:
TS:
private initAchForm() {
this.achInfoForm = this.FB.group({
password: ['',Validators.required],
confirmpassword: ['',Validators.required],
accountNumber: [null,Validators.required],
reAccountNumber: [null,Validators.required],
},
{ validator: ConfirmRoutingValidator.MatchPassword});
}
have created one file which contains these custom things:
password match file;
import { AbstractControl } from '@angular/forms';
export class ConfirmPasswordValidator {
static MatchPassword(control: AbstractControl) {
let password = control.get('password').value;
let confirmPassword = control.get('confirmPassword').value;
if (password != confirmPassword) {
control.get('confirmPassword').setErrors({ ConfirmPassword: true });
}
else {
return null;
}
}
}
export class ConfirmAccountValidator {
static MatchPassword(control: AbstractControl) {
let password = control.get('accountNumber').value;
let confirmPassword = control.get('reAccountNumber').value;
if (password != confirmPassword) {
control.get('reAccountNumber').setErrors({ ConfirmPassword: true });
}
else {
return null;
}
}
}
I am trying to add 2 validators in one section, like { validator: ConfirmRoutingValidator.MatchPassword}, { validator: ConfirmAccountValidator.MatchPassword} but get an error as
Expected 1-2 arguments, but got 3.
How can this be solved? I tried adding these values in the control names but it says value of undefined because it is not able to get those values.