SelfMetadata

export class SelfMetadata

exported from angular2/core defined in angular2/src/core/di/metadata.ts (line 118)

Specifies that an Injector should retrieve a dependency only from itself.

Example (live demo)

class Dependency { } @Injectable() class NeedsDependency { dependency; constructor(@Self() dependency:Dependency) { this.dependency = dependency; } } var inj = Injector.resolveAndCreate([Dependency, NeedsDependency]); var nd = inj.get(NeedsDependency); expect(nd.dependency instanceof Dependency).toBe(true); var inj = Injector.resolveAndCreate([Dependency]); var child = inj.resolveAndCreateChild([NeedsDependency]); expect(() => child.get(NeedsDependency)).toThrowError();

Members

toString() : string

Not Yet Documented