if (Object.prototype.hasOwnProperty.call(data, 'checklists')) {
if (Array.isArray(data.checklists)) {
data.checklists.map((dt: any) => {
dt.tasks.forEach((task: any) => {
const dataArray = new FormGroup({});
dataArray.addControl('failed', new FormControl(true, Validators.required));
dataArray.addControl('remarks', new FormControl('', Validators.required));
dataArray.addControl('task', new FormControl(task));
formArray.push(dataArray);
});
});
data.checklists.map((dt: any) => {
assetArray.push(dt.asset);
});
}
}
const formField = {
remarks: new FormControl(''),
tasks: formArray,
room: this.creds.credentials['room'],
asset: assetArray
};
return this.fb.group(formField);
Trying to figure out how to correctly set the value using addControl with new FormControl in order to create a form for both creating and editing data.
I attempted to modify it like this:
dataArray.addControl('failed', new FormControl(task['failed], Validators.required));
dataArray.addControl('remarks', new FormControl(task['remark'], Validators.required));
dataArray.addControl('task', new FormControl(task['task']));
However, the data doesn't display in the form. It does show up correctly when checked in the console. https://i.sstatic.net/oQp3L.png