I am making timer application using angularjs, counter starts after clicking on timelist, new time in timelist can be added by clicking Add Timer (popup opens then pick time using time picker). Picked time is added into list as well as localstorage onclick of OK button. But when page reloads newly added time in timelist is not getting displayed but it resides in localStorage variable (i.e. timeListDetails). I want it to be displayed whenever I add new timer.
Code to get and set localstorage value:
$scope.getStoredTimeList = function(){
timeList = JSON.parse(localStorage.getItem("timeListDetails")) || [];
if(timeList != null){
timeList.push({"hour":hour,
"minutes":minutes,
"seconds":seconds,
"convertedSec":convertedSec,
"timeFlag": true});
}
$scope.timeList = $scope.timeList.concat(timeList).unique();
localStorage.setItem("timeListDetails", JSON.stringify(timeList));
}
I have made plunker of my complete example. Clock Application review
Please tell me the solution.
This is because you are not calling the
getStoredTimeList
method when the page reloads or when initializing the app. The method:is being executed only on
sibmit()
You should first restore the values from localStorage on app initialization.