When you reload the app, your app re-initializes and all your existing data go off from memory. So you need to reset it back to your DataService's ChartTable. You can do it right after getting it back from localstorage.
if (this.ChartData != null) { this.ChartData = Object.keys(this.ChartData).map(key => ({ type: key, value: this.ChartData[key] })); this.ChartDataLength = this.ChartData.length; this.dataService.ChartTable = this.ChartData; }
You need to inject DataService into your component and you need to either write getter and setter on ChartTable or make it as public.
manpreet
Best Answer
2 years ago
So,i have a json file Uid stands for userID
i save the data on localstorage using a dataService Where i create an empty array(ChartTable) and i save this array to the localstorage with key the userID,And each time a user adds data to the storage i push his data to the ChartData table.
When i keep adding items to the array they are been pushed in the ChartTable array and its working correctly.Then i go to the profile page check the localstorage and show a chart to the user.
The problem is that when i refresh the page and go to add an other item to the ChartTable it gets overwritten and only the new data is shown to the chart.Do you know how can i solve this issue?