Skip to main content

Posts

Showing posts with the label @Injectable decorator

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 ...