Luciano Borges
Luciano Borges

Reputation: 827

What's the best way to persist information on session with AngularJS?

I have a page that show the name of user after login, but, if a press F5 the page reloads and the name does not appear. How can I persist this information in the session?

Upvotes: 0

Views: 545

Answers (3)

caffeinated.tech
caffeinated.tech

Reputation: 6548

Session Storage would be your first choice, take a look at the ngStorage module. I haven't tested it and it doesn't seem to be widely used but it's a good starting point even if you want to write your own implementation.

Though unless you have a good reason to go against cookies consider using the inbuilt $cookies service.

Upvotes: 1

Brett
Brett

Reputation: 4269

If you are targeting modern browsers (i.e. IE8+), simply use sessionStorage if you only want the data to persist for the current session, or localStorage if you want the data to persist across multiple sessions. No need to use a third-party library. It's built in already.

Upvotes: 0

Loc Nguyen
Loc Nguyen

Reputation: 9562

You can use the $cookieStore service. Docs can be found at http://docs.angularjs.org/api/ngCookies/service/$cookieStore

Upvotes: 0

Related Questions