1
votes

I have an Angular app where I have One parent component and two children components. One of the childrens have some data that the other children needs to be rendered, etc. I implemented a shared service with an Observable where children one updated the data and children two subscribes to the observable using the service and it was working good.

But then I discussed my implementation with my boss and he didn0t like the sharedService implementation, so he suggest that I communicate the children through the parent component and using EventEmitter (@Input, @Output) just as the image:

enter image description here

The thing is, that before I do any changes I would like to know witch implementation is better in terms of good practices and performance. I apprecciate any help.

1
It's a bad idea IMO. It creates an obtuse data pipeline that is harder to trace and debug than an observable service. And it probably puts the parent in violation of the SRP.The Head Rush
communicating through service will make your child component dependent on service, input-output communication ensure loosely couple of componentPraveen Soni

1 Answers

0
votes

According to me Observable is always better to communicate in your case. The disadvantage with event emitter is if a new component is added between child and the existing parent then again you need to change the code. This is not the problem with Observable service.

With Observable service you are making your component to more reactive in nature. It like Pull vs Push model. With Event emitter your are pushing the change and with Observable its always a pull.