AldoJV AldoJV - 3 months ago 8x
AngularJS Question

angularjs - localstorage not loading properly

I'm working on a little web app for a school project, I store user data on localstorage like this:

UserService.login($scope.user).then(function (response){
$scope.credentialsError = true;
$rootScope.cliente =;
localStorageService.set('cliente', $rootScope.cliente);

As long as I remain in the page, everything works fine, the user is still in $rootScope doing it's thing. The problem comes when I reload.
Upon startup i run this:

"$rootScope", "localStorageService", "$state", function($state,localStorageService, $rootScope) {
$rootScope.cliente = localStorageService.get('cliente');

Which appears to correctly get the user data from local storage. However when I request $rootScope.cliente from a controller or a template I get undefined.

Thanks for your help.


After a while i managed to solve the problem. It seems it was never about the localStorageservice, what i did was rearrange this:

angular.module('app-gp').run(["$rootScope", "localStorageService", "$state", function($rootScope, localStorageService, $state) {

and it worked...