0

I have recently started diving deeper into Angular 7 (with Ionic 3) and I have written a lot of code so far, and I have child & parent component relationships - but never like this before. I am trying to write "good" Angular code.

The problem I am now facing is, the Providers...

My Child Component needs access to the SettingsProvider but so does the Parent Component. So my question is, should I inject the SettingsProvider in both the child's and the parent's constructor or should I only inject it into the parent, and then pass it into the child via the @Input ???

1 Answer 1

3

I would inject it into both. That way the Child Component gets the SettingsProvider in a single place. If the Child component is used in multiple places, it doesn't need to be wired up to the SettingsProvider in every place.

2
  • so what's the convention basically? what's considered best practice? Commented Jan 29, 2019 at 21:23
  • I'd like to be more consistent in the future Commented Jan 29, 2019 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.