JavaScript Edu Resources. Angular Courses. React Tutorials. Join us!

Host and Visibility in Angular 2’s Dependency Injection

  • One of them is how Angular treats the relationship between host and child injectors, and the other one is how the visibility of dependencies are handled.
  • We have three nested components that all do their own thing (because that’s what components do in Angular):

    As we learned in our article on dependency injection in Angular, each component in Angular creates its own injector.

  • The injector tree allows us to define injector providers for a specific component and its children.
  • To make our code work as expected, all we have to do is to make the provider of explicitly available only for its view:

    Now, whenever a component of ’s view asks for something of type , it’ll get an instance of as expected.

  • Other child components from the outside world that ask for the same type however, won’t see this provider and will continue with the lookup in the injector tree.



Host and Visibility in Angular’s Dependency Injection by thoughtram


https://twitter.com/
https://twitter.com/intent/tweet/?text=Host%20and%20Visibility%20in%20Angular’s%20Dependency%20Injection&url=http://blog.thoughtram.io/angular/2015/08/20/host-and-visibility-in-angular-2-dependency-injection.html


Comments are closed, but trackbacks and pingbacks are open.