Convert circular structure to JSON: Angular2
I have the following object:
someObj = {
someVar: new FormControl(),
index: 100,
array1: [],
array2: [],
array3: [],
array4: []
}
and I am trying to store this in session store. For this I need to use
JSON.stringify(this.someObj);
but I am getting the error:
core.es5.js:1084 ERROR TypeError: Converting circular structure to JSON
After some research, I found that the error was because I have a formControl in my object. Doing something like this
JSON.stringify(this.someObj.searchTerm.value);
will not give an error. But I want to convert the whole object to string representation. I can obviously pass all the individual elements of an object one by one using JSON stringify, but this is not an efficient solution. Can anyone suggest a workaround?
+3
source to share
No one has answered this question yet
Check out similar questions:
fourteen