List management in AngularJS 2 / Ionic 2

73 views Asked by At

I'm building an app with AngularJS 2 / Ionic 2.

In this application I will have a component with a list. The list can be updated in two ways:

Automatic - Refresh if there is no update or if the last update was more than 30 minutes ago. Manual - If the user does not want to wait until the next update, I can update manually at any time.

The list can also be changed from other components. For example change the status of some item, delete, add, etc. The list must always be updated in the list component.

What would be the best way to manage and keep this list synchronized across all components? Through a service? Any specific library?

1

There are 1 answers

0
Jacques Cornat On BEST ANSWER

EDIT : You already asked about this : Keep list updated with Ionic 2 / Angular 2. Why do you ask again ?

To keep data synchronized across all components, IMO you have to create a service provider, (so a service declared in providers inside your main NgModule).
Every component using the list will have in its constructor something like :

constructor( private myListService: myListService, ...

In this service, you should have an Oberserver/Observable pattern, where your components will subscribe, and few methods to edit the list.
So, when components will have to update the list, they will via the service, then every change will be propagated to components subscribed.