SkipSelf
decorator
A parameter decorator to be used on constructor parameters, which tells the DI framework to start dependency resolution from the parent injector. Resolution works upward through the injector hierarchy, so the local injector is not checked for a provider.
See also
Options
Usage notes
In the following example, the dependency can be resolved when instantiating a child, but not when instantiating the class itself.
class Dependency {} @Injectable() class NeedsDependency { constructor(@SkipSelf() public dependency: Dependency) { this.dependency = dependency; } } const parent = ReflectiveInjector.resolveAndCreate([Dependency]); const child = parent.resolveAndCreateChild([NeedsDependency]); expect(child.get(NeedsDependency).dependency instanceof Dependency).toBe(true); const inj = ReflectiveInjector.resolveAndCreate([Dependency, NeedsDependency]); expect(() => inj.get(NeedsDependency)).toThrowError();
Learn more in the Dependency Injection guide.
© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v7.angular.io/api/core/SkipSelf