To store $rootScope value inside localstorage and using it in another controller on page refresh

I have a token generator function, I have to pass token parameter in every http call , so even on refresh I need to store token value intact and use it. Here is my code-

 $scope.accessTokenFunction=function() {        data={        }          $'API_url',data, config)          .success(function(data, status) {            $scope.PostDataResponse = data;           $rootScope.access_token=$scope.PostDataResponse.access_token;           console.log($rootScope.access_token);            var access_token = $rootScope.access_token                 localStorage.setItem("access_token", access_token);                 localStorage.getItem("access_token");                 console.log(access_token);                 $rootScope.acc=access_token;       })   }; 

Problem is var access_token is not able to store $rootscope.access_token on page refresh , but if I use

var access_token = 'jack' I can use this value successfully even on page refresh inside other controllers. 

What I want is $rootScope value to be assigned to access_token even on page refresh. Any help is appreciated, thanks


Category: javascript Time: 2016-07-31 Views: 120

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.401 (s). 13 q(s)