What it does
Specifies that an Injector
should retrieve a dependency only from itself.
How to use
@Injectable() class Car { constructor(@Self() public engine:Engine) {} }
Description
For more details, see the Dependency Injection Guide.
Example
class Dependency {}
@Injectable()
class NeedsDependency {
constructor(@Self() public dependency: Dependency) {}
}
let inj = ReflectiveInjector.resolveAndCreate([Dependency, NeedsDependency]);
const nd = inj.get(NeedsDependency);
expect(nd.dependency instanceof Dependency).toBe(true);
inj = ReflectiveInjector.resolveAndCreate([Dependency]);
const child = inj.resolveAndCreateChild([NeedsDependency]);
expect(() => child.get(NeedsDependency)).toThrowError();
exported from core/index defined in core/src/di/metadata.ts