am creating a modal as a component to be used on related part of my SPA. when i click the button that opens the modal i receive an exception on formgroup creation line;
export class GerekceModalComponent implements OnInit {
gerekceForm: FormGroup;
ngOnInit(): void {
----> this.gerekceForm = this.formBuilder.group({
gerekce: ''
});
}
constructor(public activeModal: NgbActiveModal, private formBuilder: FormBuilder) {
closeModal() {
this.activeModal.close('Modal Closed');
}
}
this.gerekceForm is always undefined
TypeError: Cannot read property 'valid' of undefined
the component html is as bellow
<div class="modal-header">
<h4 class="modal-title">Gerekçe</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
</button>
</div>
<form [formGroup]="gerekceForm" (ngSubmit)="submitForm()">
<div class="modal-boy">
<div class="container">
<div class="form-group shadow-textarea">
<label for="exampleFormControlTextarea6">Gerekçe içeriği</label>
<textarea class="form-control z-depth-1" id="exampleFormControlTextarea6" rows="3" placeholder="gerekçenizi yazınız"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success" [disabled]="!myForm.valid">
Submit Form
</button>
</div>
</form>
this component build according to this tutorial https://itnext.io/creating-forms-inside-modals-with-ng-bootstrap-221e4f1f5648
am I missing some thing. any help is appreciated.
myForm!! maybe that's why you getCannot read property 'valid' of undefined. Try[disabled]="!gerekceForm.valid".