Невозможно получить доступ к члену класса компонента внутри настраиваемого валидатора
Я не могу получить доступ к членам компонента внутри моего настраиваемого валидатора, даже если я привяжу к нему "this".
Вот мой угловой компонент
export class RegisterComponent implements OnInit {
registrationForm: FormGroup;
constructor(private registrationService: RegisterService, private route: ActivatedRoute) { }
ngOnInit() {
this.registrationForm = new FormGroup({
email: new FormControl(null, [Validators.required, Validators.email]),
password: new FormControl(null, [Validators.required, Validators.minLength(4)]),
passwordRepeat: new FormControl(null, [
Validators.required,
Validators.minLength(4),
this.repeatedPasswordShouldBeSame.bind(this)
])
});
}
repeatedPasswordShouldBeSame(control: FormControl): { [s: string]: boolean } {
const password = this.registrationForm.get('password').value;
const passwordRepeat = control.value;
if (password !== passwordRepeat) {
return { repeatedPasswordIsNotSame: true };
}
return null;
}
С помощью этого кода я получил "this.registrationForm is undefined"
ошибка в консоли. Что здесь не так?
Угловая версия: 8.2.5