Skip to main content

Posts

Showing posts with the label What Is Hierarchical Dependency Injectors?

What Is Injector tree? What Is Injector bubbling?

What Is Injector tree? In the Dependency Injection guide, you learned how to configure a dependency injector and how to retrieve dependencies where you need them. An application may have multiple injectors. An Angular application is a tree of components. Each component instance has its own injector. The tree of components parallels the tree of injectors. Three level component tree –  What Is Injector bubbling? Explore in detail by using below questions - 1.        What Is an entryComponents? 2.        What Are @Injectable providers? 3.        What Is Dependency Injection (DI)? I hope enjoy this post. Thank you very much reading this post.

What Are @Injectable providers? - Injector decorator

What Are @Injectable providers? The @Injectable decorator identifies services and other classes that are intended to be injected. It can also be used to configure a provider for those services. To inject the service into a component, Angular provides an Injector decorator: @Injectable(). A provider defines the set of injectable objects that are available in the injector of this module. The @Injectable decorator marks a class as available to an injector for instantiation. An injector reports an error when trying to instantiate a class that is not marked as @ Injectable . Injectors are also responsible for instantiating components. At the run-time the injectors can read class metadata in the JavaScript code and use the constructor parameter type information to determine what things to inject. Injectable decorator and metadata - @ Injectable ({   providedIn? : Type < any > | 'root' | null   factory : () => any }) To inject the service ...