I'm trying to follow the "Observable data store" pattern in Angular 2 (detailed in this blog post from Angular University) From what I understand, this means that, if I have a service called TodoStore,
I would subscribe to TodoStore.items$
so I could get all the latest updates for my to-do list in real time (as other components add, remove, or edit Todos
.
However, what if I have two components side-by-side that display different Todo
lists, filtered on the server-side? One might display Todo
s due today while another would show Todo
s due on a user-selected date.
In this case, I would not be able to use the same TodoStore
, as both would be fetching different data from the server. How do I handle sharing this service between these two components? My urge is to go back to an angular1-style getToDoList()
service method, but then I'm storing state inside a single component and can't possibly share data between multiple components without making extra API calls.
TodoStore.getItemsFromList(name)
? – olivarra1