4

I have a number of pages, and on several of them are some components that are identical from page to page. It appears that they are re-instantiated on each page/route change, and this is not the behavior that I need. I would like them to maintain their state between pages, hopefully without having to set a bunch of global variables, and then processing them to restore my state after a page/route change.

I'm not sure what kind of process Angular 2 has to determine that these particular components should be re-instantiated, but would like to know what options I might have. The component I'm concerned about has quite a process in initialize itself and display, so it will be an annoyance to users if it does this on every new page.

I know this is pretty abstract and high-level, but I'm looking for as much insight as I can get to further my research. Thanks in advance.

BBaysinger
  • 6,614
  • 13
  • 63
  • 132
  • This link has a bit of insight: https://github.com/angular/angular/issues/5275 – BBaysinger May 09 '17 at 22:27
  • Also found some useful info in the accepted answer here: http://stackoverflow.com/questions/39762485/ – BBaysinger May 09 '17 at 22:52
  • 1
    In addition to the great link that BBaysinger provided, I have a blog post on how to use an Angular service to hold and share data between components so you won't need to get the data multiple times. You can find it here: http://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/ – DeborahK May 10 '17 at 00:50

0 Answers0