У меня есть компонент регистрации, имеющий ng-переключатель компонентов
<ion-component>
<ng-container [ngSwitch]="registrationStage">
<step1 *ngSwitchCase="1"></step1>
<step2 *ngSwitchCase="2"></step2>
<step3 *ngSwitchCase="3"></step3>
<ng-container>
</ion-component>
<ion-footer>
<button (click)="goForward()">
</button>
</ion-footer>
компонент регистрации
private goForward(): void {
if (this.section !== 5) {
switch (this.section) {
case 1:
this.step1.nextStep(); // <---cannot read property invalid of undefined
this.regService.goForward();
break;
default:
break;
}
} else {
return;
}
}
компонент step1
export class Step1 {
private regForm: FormGroup;
private formBuilder: FormBuilder;
private stepTwo = false;
public constructor(formBuilder: FormBuilder) {
this.formBuilder = formBuilder;
}
public ngOnInit(): void {
console.log('loaded'); //<-- I see this in the console
this.regForm = this.formBuilder.group(
{
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required, Validators.minLength(6)]],
confirmPassword: ['', Validators.required],
},
{
validator: MustMatch('password', 'confirmPassword'),
},
);
}
public verifyAndNextStep(): void {
this.stepTwo = true;
if (this.regForm.invalid) {
return;
}
const emailPassword: EmailPassword = {
email: this.regForm.value.email,
password: this.regForm.value.password,
};
this.regService.setEmailAndPassword(emailPassword);
this.regService.goForward();
}
проблемачто я получаю сообщение об ошибке: ERROR TypeError: Cannot read property 'invalid' of undefined
указывает на вызов функции выше.Кроме того, похоже, что FormGroup не инициализируется?
Я не совсем уверен, в чем проблема, я смотрел другие посты по этому поводу:
one
два
STACK BLITZ