1

What is the best way to store/share application data across the application? I have a bunch of drop-down list that won't change very often but if they do I would reload them so I don't have to hit my web api unless the data is changed every.

Should I just create shared application service and store the data inside the service? I'm just wondering what the best practices are for this or what others are doing.

Fab
  • 904
  • 2
  • 14
  • 38
  • 1
    https://stackoverflow.com/questions/36271899/what-is-the-correct-way-to-share-the-result-of-an-angular-2-http-network-call-in/36291681#36291681 might be relevant – Günter Zöchbauer Jul 20 '17 at 15:22

1 Answers1

1

Creating a service makes total sense.

If I add a small thing, I would make the data Observable using RxJs.

Here is the guide you can refer to https://coryrylan.com/blog/angular-observable-data-services

Eddie
  • 761
  • 3
  • 9
  • 22
  • yes that's what I was thinking, should i use a Subject in a SharedApplicationService? – Fab Jul 20 '17 at 15:28
  • @Fab Sure, Subject or BehaviorSubject would do fine. But make sure you hide it from outside of class though. Expose only `Observable` by doing `return subjectItem.asObservable()` – Eddie Jul 20 '17 at 21:56