i am facing an issue, i am building a from with list of students ( formarray ). when clicked on edit of a single form array control, i want to open material modal to edit those fields & complete the student information. The issue i am facing is that as modal fields are not part of formgroup, its giving an error. How can i use 1 single control in that modal.
<div [formGroup]="form" class="container">
<div formArrayName="students">
<button type="button" (click)="addStudent()"> Add </button>
<div class="row" *ngFor="let control of students.controls; let i = index">
<!-- All other fields -->
<button type="button" class="close" aria-label="Close" (click)="openModal(studentModal, i)">
close </button>
</div>
</div>
</div>
<ng-template #studentModal let-modal>
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true"><i class="material-icons">{{'close' | translate}}</i></span>
</button>
</div>
<div class="modal-body">
<div class="border-apply">
<div class="m-b-20">
<div class="contact-grid">
<!-- Display single formarray control -->
</div>
</div>
</div>
</div>
</ng-template>
Meanwhile component class is
this.form = this.fb.group({
students: this.fb.array([])
});
get students(): FormArray {
return this.form.get('students') as FormArray;
}
addStudent(): void {
this.sensors.push(this.fb.group({
studentUniqueID: new FormControl(),
name: new FormControl(''),
grade: new FormControl('')
}),
]));
}
openModal(content, id): void {
this.toEditStudentControl = this.students.controls[id];
this.editIndex = id;
this.modalService.open(content, { size: 'sm' });
}