I think it depends. I think services are most useful when communicating from a deeply nested child component directly to a high level parent component. I should have clarified that point because passing @Input properties down a deep chain isn’t as cumbersome as managing @Output properties back up the component chain.
So I guess to answer your question, it’s probably better to just pass @Input properties down to a dumb component but I wouldn’t say it’s an anti pattern to use a service
I agree with John, it depends. I think you could build your service to implement an interface that could make it easily reusable. For example, if you had an ISummaryService that may represent a few levels deep in your component tree. But it would make sense that you may have a mixture of input/output when you get a few levels deep.
I tend to view the deeper I go they get simpler and less stateful all the way back to the root. So the injected service becomes less important and the input/output becomes more valid. And a lot of times the deeper I go the more it is to simplify a larger component and make the smaller pieces more testable.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for this post!
About "Prop drilling" I have a question:
I have this hierarchy:
-smart component
-dumb component
-dumb component
....
- the last dumb component
Isn't it anti-pattern to inject a service into a dumb component?
I think it depends. I think services are most useful when communicating from a deeply nested child component directly to a high level parent component. I should have clarified that point because passing @Input properties down a deep chain isn’t as cumbersome as managing @Output properties back up the component chain.
So I guess to answer your question, it’s probably better to just pass @Input properties down to a dumb component but I wouldn’t say it’s an anti pattern to use a service
I agree with John, it depends. I think you could build your service to implement an interface that could make it easily reusable. For example, if you had an
ISummaryService
that may represent a few levels deep in your component tree. But it would make sense that you may have a mixture of input/output when you get a few levels deep.I tend to view the deeper I go they get simpler and less stateful all the way back to the root. So the injected service becomes less important and the input/output becomes more valid. And a lot of times the deeper I go the more it is to simplify a larger component and make the smaller pieces more testable.