GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs
  • Tutorials
  • Playground
  • Reference
  • code
  • SkipSelf
  • Optional

This view

  • Original page
  • New address

GeezerVison is showing angular.dev — Self • Angular

API

@Self();

Description

Parameter decorator to be used on constructor parameters, which tells the DI framework to start dependency resolution from the local injector.

Resolution works upward through the injector hierarchy, so the children of this class must configure their own providers or be prepared for a null result.

Usage Notes

In the following example, the dependency can be resolved by the local injector when instantiating the class itself, but not when instantiating a child.

class Dependency {}

        @Injectable()
        class NeedsDependency {
          constructor(@Self() public dependency: Dependency) {}
        }

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

        expect(nd.dependency instanceof Dependency).toBe(true);

        const child = Injector.create({
          providers: [{provide: NeedsDependency, deps: [[new Self(), Dependency]]}],
          parent: inj,
        });
        expect(() => child.get(NeedsDependency)).toThrowError();
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.