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
  • Dependency Injection Guide

This view

  • Original page
  • New address

GeezerVison is showing angular.dev — Inject • Angular

API

@Inject(token: string);
@Inject(token: any);

Usage Notes

The following example shows a class constructor that specifies a custom provider of a dependency using the parameter decorator.

When @Inject() is not present, the injector uses the type annotation of the parameter as the provider.

class Engine {}

        @Injectable()
        class Car {
          constructor(public engine: Engine) {} // same as constructor(@Inject(Engine) engine:Engine)
        }

        const injector = Injector.create({
          providers: [
            {provide: Engine, deps: []},
            {provide: Car, deps: [Engine]},
          ],
        });
        expect(injector.get(Car).engine instanceof Engine).toBe(true);
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.