From e51ec671a57c0a96d1fdd9bd327114e894b874ea Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Thu, 14 Nov 2019 11:59:13 -0800 Subject: [PATCH] fix(ivy): extend assertion in `directiveInject` function to support IcuContainers (#33832) Prior to this commit the assert that we have in `directiveInject` (assert introduced recently) didn't include IcuContainer TNode type and as a result, the error is thrown in case pipes with dependencies are used inside ICUs. This commit extends the assert to allow for IcuContainer TNode types. PR Close #33832 --- packages/core/src/render3/instructions/di.ts | 3 +- packages/core/test/acceptance/di_spec.ts | 35 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/core/src/render3/instructions/di.ts b/packages/core/src/render3/instructions/di.ts index fc97298d17..28ee4880e7 100644 --- a/packages/core/src/render3/instructions/di.ts +++ b/packages/core/src/render3/instructions/di.ts @@ -47,7 +47,8 @@ export function ɵɵdirectiveInject( if (lView == null) return ɵɵinject(token, flags); const tNode = getPreviousOrParentTNode(); ngDevMode && assertNodeOfPossibleTypes( - tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer); + tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer, + TNodeType.IcuContainer); return getOrCreateInjectable( tNode as TDirectiveHostNode, lView, resolveForwardRef(token), flags); } diff --git a/packages/core/test/acceptance/di_spec.ts b/packages/core/test/acceptance/di_spec.ts index 7b00a079ef..571c5dd2bb 100644 --- a/packages/core/test/acceptance/di_spec.ts +++ b/packages/core/test/acceptance/di_spec.ts @@ -1824,4 +1824,39 @@ describe('di', () => { expect(directive.other).toBe('otherValue'); }); }); + + it('should support dependencies in Pipes used inside ICUs', () => { + @Injectable() + class MyService { + transform(value: string): string { return `${value} (transformed)`; } + } + + @Pipe({name: 'somePipe'}) + class MyPipe { + constructor(private service: MyService) {} + transform(value: any): any { return this.service.transform(value); } + } + + @Component({ + template: ` +
{ + count, select, + =1 {One} + other {Other value is: {{count | somePipe}}} + }
+ ` + }) + class MyComp { + count = '2'; + } + + TestBed.configureTestingModule({ + declarations: [MyPipe, MyComp], + providers: [MyService], + }); + const fixture = TestBed.createComponent(MyComp); + fixture.detectChanges(); + + expect(fixture.nativeElement.innerHTML).toContain('Other value is: 2 (transformed)'); + }); });