-1

Currently in my app I have built a crud page, I'll use heroes as an example. I have a table which lists all the heroes which are retrieved via an API call. Each of the crud functions are their own components (view component, edit component etc). Each one of those pages is displayed via a routerlink.

How do I correctly share data between these components? From what In the documentation the author will do another API request when they want to edit a hero instead of just selecting the hero out of the array.

What is the correct way to access the array of heroes? I think I'm supposed to use the hero.service, do I just create an array in the service which is populated when the first api call to get all the heroes is made?

Tom Headifen
  • 1,885
  • 1
  • 18
  • 35

1 Answers1

1

Yes. If you are not concerned about getting "dirty" data, then you can define the array of heroes in the service. You set them when the data is first retrieved, then you access them any time you want hero data.

The downside of this is that the user will hold on to the list of heroes until they exit the application. If any other user modifies the hero data, this user won't get their changes.

This is fine in a situation where the data won't change often (like the list of US states.) But may not be desired in a real CRUD app.

DeborahK
  • 57,520
  • 12
  • 104
  • 129