7

I know lots have already asked this question but none of them gave clear answer. I just want to store the state of component when it navigates to another and then come back to previous one. I know we can save the data in service and then fetch the dats back to component. But, I think this is easy but not the better solution when the component is too complex. I read some router reuse things but non of them work in angular 2.

2
  • Can you provide the questions that don't provide a clear answers? This is a possible duplicate and have answered many times before Commented Jul 24, 2017 at 21:15
  • You can't save data in a component since when its destructed the data will go away Commented Jul 24, 2017 at 21:15

1 Answer 1

7

There are several options:

1) Use a service. This is actually one of the best ways if the data is complex. I have a simple example here: https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/

2) Routing parameters. You can specify required, optional, or query parameters. See this for more information: Sending data with route.navigate in Angular 2

If you are looking for information on the router reuse strategies, you can find some information here: https://medium.com/@juliapassynkova/angular-2-component-reuse-strategy-9f3ddfab23f5

Sign up to request clarification or add additional context in comments.

4 Comments

Asked this question around July 2017 and now in 2018, what I understand is simply save the data in service file and again use that data when you comes back on that page. Hence other answer still didn't come from @angular team.
I don't believe that the Angular team monitors these forums. Stackoverflow is community supported. We are all just volunteers here.
I updated my answer above to provide information on router reuse as well if that is what you are really looking for?
this is why I don't want to use Ionic4 (angular based routing) and keep Ionic3 (it keeps the component state automaticly!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.