Я работаю с ionic 5 и Angular 9. Я пытаюсь создать реактивную форму, но получаю сообщение об ошибке «Нет доступа к значению для управления формой с именем:« фамилия »».
Вот мой код:
export class ModalComponent implements OnInit {
public form: FormGroup;
constructor(private modalController: ModalController,
private formBuilder: FormBuilder) { }
ngOnInit(): void {
this.initForm();
}
public close(): void {
// using the injected ModalController this page
// can "dismiss" itself and optionally pass back data
this.modalController.dismiss({
'dismissed': true
});
}
public initForm(): void {
this.form = this.formBuilder.group({
firstname: ['', Validators.required],
lastname: ['', Validators.required]
});
}
logForm(){
console.log(this.form.value)
}
}
<form [formGroup]="form" (ngSubmit)="logForm()" novalidate>
<ion-item>
<ion-label>Last name</ion-label>
<ion-input type="text" formControlName="lastname"></ion-input>
</ion-item>
</form>
Редактировать: я только что нашел проблему. Мне не хватало импорта IonicModule в моем модуле.
public async presentModal(): Promise<void> { const modal = await this.modalController.create({ component: ModalComponent }); return await modal.present(); }
- person Alyaura   schedule 23.03.2020