I am working on an Angular component where I am adding some validators to the form in the constructor. However, I would like to add additional validators in my ngOnInit method. How can I accomplish this?
export class ResetPasswordComponent implements OnInit {
constructor(
private fb: FormBuilder,
private route: ActivatedRoute,
private forgotPasswordService: ForgotPasswordService,
private configService: ConfigService,
private usersService: UsersService
) {
this.blacklistedPasswords = this.configService.config.blacklistedPasswords;
this.formGroup = this.fb.group(
{
password: ['', [Validators.required, Validators.minLength(8)]],
confirmPassword: ['', [Validators.required, Validators.minLength(8)]]
},
{
validator: Validators.compose([
passwordStrengthValidator('password', 'confirmPassword'),
blacklistedPasswordValidator(
'password',
'confirmPassword',
this.blacklistedPasswords
)
])
}
);
}
ngOnInit() {
}
}
How can I append another validator to the component's ngOnInit method? For example, I want to add a validator like matchingValidator('password', 'confirmPassword'), similar to passwordStrengthValidator and blacklistedPasswordValidator. How can I achieve this?
I am new to Angular, so thank you for your help!