user12250118
user12250118

Reputation:

Angular 8: Input/Output vs Services

Are there any advantages of applying @Input/Output vs Services (Publish/Subscribe) in Angular? Input Output can only talk between Parent-Child; however Services can do both, (Parent-Child, Sibling, Different components).

So as business requirements, architecture changes, seems like Services have more flexibility? And services more Microservices? So why use Input/Output?

I am trying to learn benefits, and good principles.

Upvotes: 2

Views: 992

Answers (1)

Kyle Anderson
Kyle Anderson

Reputation: 754

There are a lot of factors that go into that decision. There is no 'right' answer.

For example for a lot of your 'dumb' components you should be using inputs/outputs as you generally don't want them to know too much about your application structure and have a bunch of dependencies... also communication through services doesn't generally work well for component reuse. Say for example I have 2 of the same child component on a page that I want to display different data. How do I do that if I am communicating with them via services? It is simple with inputs/outputs.

Higher level components are more likely to need to interact and communicate with services.

Upvotes: 1

Related Questions