DEV Community

Discussion on: 10 Tips for Awesome Angular Apps

Collapse
 
gigitux profile image
Luigi Teschio

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?

Collapse
 
joerter profile image
John Oerter

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

Collapse
 
jmarbutt profile image
Jonathan Marbutt

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.