I seem to be missing a crucial element in my endeavor to save and retrieve an array in local storage within my Angular 4 application.
The array is fetched from the server and stored in a variable named 'aToDo' with type 'any', like so:
{"qoption":"Trap Surveyor (<em>Competency for CM OAP<\/em>)"}
It is then saved in local storage using the following code snippet:
localStorage.setItem('aToDo',JSON.stringify(this.aToDo));
Upon retrieval from local storage, it is parsed back into the 'aToDo' variable as follows:
this.aToDo = JSON.parse(localStorage.getItem('aToDo'));
A console.log of 'this.aToDo' displays:
{"qoption":"Trap Surveyor (<em>Competency for CM OAP<\/em>)"}
However, at this point, something seems to have gone wrong. Attempting to access 'this.aToDo.qoption' results in 'undefined', and when trying to iterate over the array using *ngFor, I encounter the error message:
Error: Cannot find a differ supporting object '{"qoption":"Trap Surveyor (<em>Competency for CM OAP<\/em>)"}' of type 'string'.
Can anyone help me identify where I went wrong? Thanks - Tom