I am tinkering this code now and I would like to make use of localStorage to save the state of my widgets on my dashboard so that when the user goes back to my application the position of the widgets are intact and saved but everytime I refresh the browser it goes back to its current scope.dashboards state which I have no idea on how will I fix. I used ngStorage module for localStorage
var modInProgr = false;
$scope.$watch("dashboards['1'].widgets", function(newVal, oldVal) {
if (!modInProgr) {
modInProgr = true;
// modify dashboards
$scope.$storage = $localStorage;
$localStorage.sample = $scope.dashboards[1];
console.log($localStorage.sample);
}
$timeout(function() {
modInProgr = false;
}, 0);
$scope.dashboard = $localStorage.sample;
}, true);
// init dashboard
$scope.dashboard = $localStorage.sample;
I have a button that the user clicks to call this function:
That saves it to local storage. I also save it to database incase local storage expires or gets deleted.
then when gridster is loading I do this: