Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

SkipSelf

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) {}
}

const parent = Injector.create({providers: [{provide: Dependency, deps: []}]});
const child = Injector.create({
  providers: [{provide: NeedsDependency, deps: [Dependency]}],
  parent,
});
expect(child.get(NeedsDependency).dependency instanceof Dependency).toBe(true);

const inj = Injector.create({
  providers: [{provide: NeedsDependency, deps: [[new Self(), Dependency]]}],
});
expect(() => inj.get(NeedsDependency)).toThrowError();