简体   繁体   中英

Angular synchronize objects between components

I am creating an Angular 4 app and I am having some problems with my data concept.

I have an app with 3 components. Each of this components has some settings like name, date, List... which are different for each component. Now I am trying to implement the ability to synchronize this settings between the components. For example I want to enable that the component 1 synchronizes the date with component 2. So if I change the date on component 2 it also should change on component 1. I want to enable/disable this in my app. So if I don´t want to synchronize I disable it and each component has it own settings again. And it should be possible to synchronize with different components. So component 1 synchronizes date with component 2. And component 1 synchronizes List with component 3.

I already have implemented something simliar in Java with the Guava EventBus and I think that this might be possible to do with Observer but I am not sure how to do it correctly.

This is a great case of using Shared services or Ngrx .

The data is maintained throught the application using these two ways. My suggestion is to go for Ngrx if you app size is huge and huge shared services for small to medium apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM