test(ivy): add injection canonical specs (#22595)

PR Close #22595
This commit is contained in:
Misko Hevery
2018-03-04 20:21:23 -08:00
committed by Kara Erickson
parent f13f4db9dc
commit 2fee5cc095
14 changed files with 403 additions and 128 deletions

View File

@ -174,7 +174,7 @@ export function diPublic(def: DirectiveDef<any>): void {
}
/**
* Searches for an instance of the given directive type up the injector tree and returns
* Searches for an instance of the given type up the injector tree and returns
* that instance if found.
*
* If not found, it will propagate up to the next parent injector until the token
@ -187,15 +187,18 @@ export function diPublic(def: DirectiveDef<any>): void {
*
* static ngDirectiveDef = defineDirective({
* type: SomeDirective,
* factory: () => new SomeDirective(inject(DirectiveA))
* factory: () => new SomeDirective(directiveInject(DirectiveA))
* });
* }
*
* NOTE: use `directiveInject` with `@Directive`, `@Component`, and `@Pipe`. For
* all other injection use `inject` which does not walk the DOM render tree.
*
* @param token The directive type to search for
* @param flags Injection flags (e.g. CheckParent)
* @returns The instance found
*/
export function inject<T>(token: Type<T>, flags?: InjectFlags, defaultValue?: T): T {
export function directiveInject<T>(token: Type<T>, flags?: InjectFlags, defaultValue?: T): T {
return getOrCreateInjectable<T>(getOrCreateNodeInjector(), token, flags, defaultValue);
}