0

I gave both of my controller a service that they use to pass the data, but when I refresh the page the data in the service gets empty, is there a way to save this data globally or at least get back to the first page when refreshing?

Yanif
  • 1
  • 1

1 Answers1

1

You'll need to store the data, as data in angular services is ephemeral.

You have a number of options depending on the type and purpose of the data:

  • Database (mySQL, MongoDB etc for data collections).
  • Local browser storage (cookies, HTML5 Web Storage etc for session related data).
  • Cache (Redis etc for web server session caching).
Seonixx
  • 468
  • 3
  • 16
  • Could you give me more information about using local browser storage? – Yanif Dec 23 '15 at 11:06
  • Web storage is effectively a follow on from cookies, except it is far more intuitive, secure and flexible. You have two different storage options, either session or local (session storage is deleted on browser close, local is persistent, even after browser close, reloads etc). You store data in a key-value pair format, much the same as object literal syntax. Have a read of the mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API – Seonixx Dec 23 '15 at 11:22