Control the dependency lookup with @Host, @SkipSelf and @Optional

Share this video with your friends

Send Tweet

Very differently to AngularJS (v1.x), Angular now has a hierarchical dependency injector. That allows to specify service definitions as well as the service lifetime at various levels in our application. Whenever a service is requested, Angular will walk up the component tree and search for a matching definition. While in most cases that's perfectly fine, often you may want to take control over the dependency lookup. In this lesson we will learn how, by applying @Host(), @SkipSelf() and @Optional().

ganqqwerty
ganqqwerty
~ 5 years ago

When can the @Optional be useful in real situation? Can you come up with the example?