InjectableMetadata

export class InjectableMetadata

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

A marker metadata that marks a class as available to Injector for creation.

Example (live demo)

@Injectable() class UsefulService {} @Injectable() class NeedsService { constructor(public service:UsefulService) {} } var injector = Injector.resolveAndCreate([NeedsService, UsefulService]); expect(injector.get(NeedsService).service instanceof UsefulService).toBe(true);

Injector will throw NoAnnotationError when trying to instantiate a class that does not have @Injectable marker, as shown in the example below.

class UsefulService {} class NeedsService { constructor(public service:UsefulService) {} } var injector = Injector.resolveAndCreate([NeedsService, UsefulService]); expect(() => injector.get(NeedsService)).toThrowError();

Constructor

constructor()

Not Yet Documented