DEV Community

Discussion on: Looking for Angular Architecture Advise

Collapse
 
paulmojicatech profile image
paulmojicatech

Personally, I try to follow the smart component / dumb component pattern. With this, my parent component handles all the data to pass down to the child / dumb components. If a child component has some interaction that other siblings need to know about, I emit something from the child which will update the observable on the parent. I have been implementing this by injecting a service to the parent to that will contain a method to return an observable. In the service, I have a private BehaviorSubject so when the method is called to get the observable from the component, the method returns the behavior subject with .asObservable(). I also have an updateState method that will take a key and value as parameters. Here I use .getValue in the BehaviorSubject, update the key with the value, and cal .next() on the subject. In the template, I use async pipe to pass the data to the children. I have found it works pretty well for me and gives me a pattern to separate the business logic from the presentational component.