Resolution modifiers : Angular dependency injection resolution mechanism of the service starts from component and stops either when a service is found or NUllInjector is reached. This is the default resolution and it can be changed using Resolution Modifier.
Table of Contents
Resolution modifiers fall into three categories.
@Optional() allows Angular to consider a service you inject to be optional and does not throws the error when the search for the service fails.
@Self is used, Angular will only look for a value that is bound on the component injector for the element that this Directive/Component exists on.
@Host is used, Angular will look for a value that is bound on either the component injector for the element that this Directive/Component exists on, or on the injector of the parent component. Angular calls this parent component the “host”.
Source code available for download
The source code is available on Stackblitz of the Angular Dependency Injection – Resolution modifiers – @Self or @Optional @Host
Demo Application URL: URL or download the project sources from https://stackblitz.com/edit/inject-and-injectable-qwnzso