Last active
December 13, 2015 23:49
-
-
Save a7medfahmy94/d4be8db4e24021e61898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app').run(function($rootScope, $state, localStorageService) { | |
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { | |
var prefix = "stateParams."; | |
var fromStateName = prefix + fromState.name; | |
var toStateName = prefix + toState.name; | |
var f = true; | |
for (var k in toState.params) { | |
f = f && (JSON.stringify(toParams[k]) == JSON.stringify(toState.params[k])); | |
} | |
if (f && localStorageService.get(toStateName) != null) { | |
event.preventDefault(); | |
var savedToParams = localStorageService.get(toStateName); //retrieving toParams from local storage | |
localStorageService.remove(toStateName); | |
for (var k in toState.params) { | |
toParams[k] = savedToParams[k]; //update only the params {} not url params | |
} | |
$state.transitionTo(toState,toParams); | |
} else { | |
var toSave = {}; | |
for (var k in toState.params) { | |
toSave[k] = toParams[k]; //save only the params {} not url params | |
} | |
localStorageService.set(toStateName,toSave); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment