fix(ivy): support forward refs in @Inject annotations (#27069)
PR Close #27069
This commit is contained in:
parent
123da1a8c2
commit
e6e590479e
|
@ -8,6 +8,7 @@
|
|||
|
||||
import './ng_dev_mode';
|
||||
|
||||
import {resolveForwardRef} from '../di/forward_ref';
|
||||
import {InjectionToken} from '../di/injection_token';
|
||||
import {InjectFlags} from '../di/injector_compatibility';
|
||||
import {QueryList} from '../linker';
|
||||
|
@ -2653,6 +2654,7 @@ export function directiveInject<T>(token: Type<T>| InjectionToken<T>): T;
|
|||
export function directiveInject<T>(token: Type<T>| InjectionToken<T>, flags: InjectFlags): T;
|
||||
export function directiveInject<T>(
|
||||
token: Type<T>| InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
token = resolveForwardRef(token);
|
||||
return getOrCreateInjectable<T>(
|
||||
getPreviousOrParentTNode() as TElementNode | TContainerNode | TElementContainerNode,
|
||||
getViewData(), token, flags);
|
||||
|
|
|
@ -248,6 +248,9 @@
|
|||
{
|
||||
"name": "__extends"
|
||||
},
|
||||
{
|
||||
"name": "__forward_ref__"
|
||||
},
|
||||
{
|
||||
"name": "__read"
|
||||
},
|
||||
|
@ -557,6 +560,9 @@
|
|||
{
|
||||
"name": "firstTemplatePass"
|
||||
},
|
||||
{
|
||||
"name": "forwardRef"
|
||||
},
|
||||
{
|
||||
"name": "generateExpandoInstructionBlock"
|
||||
},
|
||||
|
@ -1040,6 +1046,9 @@
|
|||
{
|
||||
"name": "resolveDirectives"
|
||||
},
|
||||
{
|
||||
"name": "resolveForwardRef"
|
||||
},
|
||||
{
|
||||
"name": "saveNameToExportMap"
|
||||
},
|
||||
|
|
|
@ -260,6 +260,9 @@
|
|||
{
|
||||
"name": "__extends"
|
||||
},
|
||||
{
|
||||
"name": "__forward_ref__"
|
||||
},
|
||||
{
|
||||
"name": "__read"
|
||||
},
|
||||
|
@ -602,6 +605,9 @@
|
|||
{
|
||||
"name": "firstTemplatePass"
|
||||
},
|
||||
{
|
||||
"name": "forwardRef"
|
||||
},
|
||||
{
|
||||
"name": "generateExpandoInstructionBlock"
|
||||
},
|
||||
|
@ -1061,6 +1067,9 @@
|
|||
{
|
||||
"name": "resolveDirectives"
|
||||
},
|
||||
{
|
||||
"name": "resolveForwardRef"
|
||||
},
|
||||
{
|
||||
"name": "restoreView"
|
||||
},
|
||||
|
|
|
@ -215,6 +215,17 @@ describe('providers', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('@Inject annotation wrapped in forwardRef', () => {
|
||||
// @Inject(forwardRef(() => GREETER))
|
||||
expectProvidersScenario({
|
||||
parent: {
|
||||
providers: [{provide: GREETER, useValue: {greet: 'Value'}}],
|
||||
componentAssertion:
|
||||
() => { expect(directiveInject(forwardRef(() => GREETER)).greet).toEqual('Value'); }
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue