@SkipSelf

This is the documentation for Angular 6.
You can switch to the latest version Angular 7.

A constructor parameter decorator that tells the DI framework that dependency resolution should start from the parent injector.

constructor(@SkipSelf() service: Service) {}

Example

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();