Retrieves an instance from the injector based on the provided token.
If not found:
- Throws NoProviderError
if no notFoundValue
that is not equal to
Injector.THROW_IF_NOT_FOUND is given
- Returns the notFoundValue
otherwise
Example (live demo)
var injector = ReflectiveInjector.resolveAndCreate(
provide("validToken", {useValue: "Value"})
);
expect(injector.get("validToken")).toEqual("Value");
expect(() => injector.get("invalidToken")).toThrowError();
Injector returns itself when given Injector as a token.
var injector = ReflectiveInjector.resolveAndCreate();
expect(injector.get(Injector)).toBe(injector);
Source
dynamic get(dynamic token, [dynamic notFoundValue]);