Having trouble passing data from a dialog back to the parent component. Specifically, I'm struggling with updating the value of an array in the `afterClosed` function. I've tried using `patchValue` and `setValue`, but it doesn't seem to be working. Can anyone offer some guidance?
MAT DIALOG
OnInit(): void {
this.fg = this.fb.group({
id: [],
qty: [],
displayArray: this.fb.array([this.CreateItem()]),
});
this.fg.get('qty').valueChanges.subscribe((res) => {
for (let i = this.displayArray.length; i < res; i++) {
this.displayArray.push(this.CreateItem());
}
});
this.data = this.fg.get('qty').setValue(this.data.qty);
}
CreateItem(): FormGroup {
return this.fb.group({
MoreItem: [''],
});
}
get displayArray(): FormArray {
return this.fg.get('displayArray') as FormArray;
}
inMemoryList() {
this.http.get<MyDTO>('api/users').subscribe((test) => (this.myDTO = test));
}
save() {
this.dialogRef.close([this.data.qty]);
}
MY PARENT COMPONENT
CreatesetItem(): FormGroup {
return this.fb.group({
ListItem: [''],
});
}
item(): FormGroup {
return this.fb.group({
qty: [],
name: [''],
});
}
get setItem(): FormArray {
return this.fg.get('setItem') as FormArray;
}
get Info(): FormArray {
return this.fg.get('Info') as FormArray;
}
openAlertDialog(index: number) {
const dialogRef = this.dialog.open(AlertDialogComponent, {
data: {
qty: this.fg.value.Info[index].qty,
name: this.fg.value.Info[index].name,
},
});
dialogRef.afterClosed().subscribe((result) => {
for (let i = 0; i < result; i++) {
this.setItem.push(this.CreatesetItem());
}
for (let i = 0; i < result; i++) {
this.setItem.at(i).patchValue({ qty: result.qty });
}
});
}