I would like to store a formgroup object in database. I am not able to stringify this object because of circular dependency. Is there a workaround for this in angular?
form ={ coursename: new FormControl('', Validators.required), content: new FormControl('',Validators.required), }
// your code
const form = {
coursename: new FormControl("", Validators.required),
content: new FormControl("", Validators.required),
};
// since new FormControl() create an object with circular reference,
// so instead of taking the FormControl object, we can use FormControl.value
// which return the actual data object with no circular reference
// updated code
courseNameControl = new FormControl("", Validators.required);
contentControl = new FormControl("", Validators.required);
const form = {
coursename: courseNameControl.value,
content: contentControl.value,
}
// now you can stringify the form
const stringifyForm = JSON.stringify(form);