ottz0
ottz0

Reputation: 2605

Sharing data in Angular

I have a hotel page with information about a hotel and when you click book you go to a booking page.

When you get to the booking page you will then be asked for name details etc.

However I need to pass other data from the hotel page to it such as a summary of the hotel and the room configration as a confirmation before they book(so I need this data again).

My question is if the user refreshes the page?

Will using $state or UIrouter or having the data as a service cause the data to be lost? Like flash or non persistent data?

If so would I be better when the user clicks the button it saves it as a session cookie in which I can pick it up on the next page?

Upvotes: 2

Views: 51

Answers (1)

moribvndvs
moribvndvs

Reputation: 42497

It will. You need to persist the information somewhere durable. Either send it to the server, or store it client side using localStorage or something similar.

Refreshing the browser is like restarting the app, only it (if you designed your application correctly) pick up in the same location you were at. However, all information is wiped, except for durable stores like local data, cookies, local database, and obviously it won't affect the server.

So choose the most appropriate durable store based on your application's needs.

Upvotes: 3

Related Questions