in your controller after receiving the token from the server
$scope.token = token;
you can say
localStorage.setItem("token", $scope.token);
then when you want to get a token (say, in another controller), all you have to say is
$scope.token = localStorage.getItem("token");
Also, if they open the application again, you can even check if they have a token
if(localStorage.getItem("token") !== null && localStorage.getItem("token") !== ""){//go ahead and authenticate them without getting a new token.}
Also keep in mind that when you log out, if you want to clear the token, you can simply set
localStorage.setItem("token", "");
but keep in mind that you can only set local storage on strings, not boolean or null.
source share