Reputation: 839
I pass url parameters stored in a localstorage to get details of a particular item. i want to delete localstorage variable after view is loaded, but what i'm experincing is, the localstorage variables get deleted before the view is loaded preventing the data to load correctly
$scope.pushpayment_id = localStorage.getItem("pushpayment_id")
$scope.pushshop_id = localStorage.getItem("pushshop_id")
$scope.pushmessage = localStorage.getItem("push_message")
var startapp=function() {
if($scope.pushmessage== "payment"){
$location.path('/tab/new_payment_push/'+ $scope.pushpayment_id + '/' + $scope.pushshop_id);
}
}
localStorage.removeItem("pushpayment_id")
localStorage.removeItem("pushshop_id")
localStorage.removeItem("push_message")
Upvotes: 1
Views: 1787
Reputation: 2203
An Angular solution can be this:
When the locations change successfully you can make your operations, also can control from what path are you comming and where are you going.
EDIT place this on your .run()
, tell me if you need more information about it.
$rootScope.$on('$locationChangeSuccess', function(ev, newUrl, oldUrl, newState, oldState){
if(newUrl === '/myLocation/To/Delete'){
localStorage.clear();
}
});
See here more information about the events of $location
Upvotes: 1
Reputation: 8670
you could use the load event callback to remove your localStorage.
in javascript, use
$(window).load(function() {
//What you need to do.
})
Make sure you have Jquery installed for before trying, or else you will get and error.
You can learn more on the window object in Javascript on W3School
Hopes it helps !
Upvotes: 0
Reputation: 108
You could clear localStorage when the window is done loading with jQuery like this:
$(window).load(function () {
localStorage.clear();
});
If you want to use pure javascript to detect if the page is done loading, you could try this option: https://stackoverflow.com/a/7088499/5709703
Upvotes: 0