/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import {QueryList, TemplateRef, ViewContainerRef} from '@angular/core'; import {SelectorFlags} from '@angular/core/src/render3/interfaces/projection'; import {AttributeMarker, detectChanges, ΔdefineComponent, ΔdefineDirective, ΔdirectiveInject, ΔloadViewQuery, ΔqueryRefresh, Δreference, ΔtemplateRefExtractor, ΔviewQuery} from '../../src/render3/index'; import {Δbind, Δcontainer, ΔcontainerRefreshEnd, ΔcontainerRefreshStart, Δelement, ΔelementContainerEnd, ΔelementContainerStart, ΔelementEnd, ΔelementProperty, ΔelementStart, ΔembeddedViewEnd, ΔembeddedViewStart, Δinterpolation1, Δprojection, ΔprojectionDef, Δtemplate, Δtext, ΔtextBinding} from '../../src/render3/instructions/all'; import {RenderFlags} from '../../src/render3/interfaces/definition'; import {NgForOf, NgIf} from './common_with_def'; import {ComponentFixture, createComponent, getDirectiveOnNode, renderComponent, toHtml} from './render_util'; describe('content projection', () => { it('should project content', () => { /** *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); } }, 2); /** * content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
content
'); }); it('should project content when is at a template root', () => { /** */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); } }, 1); /** content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('content'); }); it('should project content with siblings', () => { /** */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); } }, 1); /** * * before *
content
* after *
*/ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, 'before'); ΔelementStart(2, 'div'); { Δtext(3, 'content'); } ΔelementEnd(); Δtext(4, 'after'); } ΔelementEnd(); } }, 5, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('before
content
after
'); }); it('should re-project content when root.', () => { /**
*/ const GrandChild = createComponent('grand-child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); } }, 2); /** */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'grand-child'); { Δprojection(1); } ΔelementEnd(); } }, 2, 0, [GrandChild]); /** HelloWorld! */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'b'); Δtext(2, 'Hello'); ΔelementEnd(); Δtext(3, 'World!'); } ΔelementEnd(); } }, 4, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual('
HelloWorld!
'); }); it('should project components', () => { /**
*/ const Child = createComponent('child', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); } }, 2); const ProjectedComp = createComponent('projected-comp', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { Δtext(0, 'content'); } }, 1); /** * * * */ const Parent = createComponent('parent', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δelement(1, 'projected-comp'); } ΔelementEnd(); } }, 2, 0, [Child, ProjectedComp]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual('
content
'); }); it('should project components that have their own projection', () => { /**
*/ const Child = createComponent('child', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); } }, 2); /**

*/ const ProjectedComp = createComponent('projected-comp', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'p'); Δprojection(1); ΔelementEnd(); } }, 2); /** * * *
Some content
* Other content *
*
*/ const Parent = createComponent('parent', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'projected-comp'); { ΔelementStart(2, 'div'); Δtext(3, 'Some content'); ΔelementEnd(); Δtext(4, 'Other content'); } ΔelementEnd(); } ΔelementEnd(); } }, 5, 0, [Child, ProjectedComp]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '

Some content
Other content

'); }); it('should project containers', () => { /**
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); } }, 2); /** * * ( * % if (value) { * content * % } * ) * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: {value: any}) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, '('); Δcontainer(2); Δtext(3, ')'); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(2); { if (ctx.value) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δtext(0, 'content'); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 4, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
()
'); parent.value = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
(content)
'); parent.value = false; detectChanges(parent); expect(toHtml(parent)).toEqual('
()
'); }); it('should project containers into root', () => { /** */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); } }, 1); /** * * % if (value) { * content * % } * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: {value: any}) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δcontainer(1); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(1); { if (ctx.value) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δtext(0, 'content'); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual(''); parent.value = true; detectChanges(parent); expect(toHtml(parent)).toEqual('content'); parent.value = false; detectChanges(parent); expect(toHtml(parent)).toEqual(''); }); it('should project containers with if-else.', () => { /**
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); } }, 2); /** * * ( * % if (value) { * content * % } else { * else * % } * ) * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: {value: any}) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, '('); Δcontainer(2); Δtext(3, ')'); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(2); { if (ctx.value) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δtext(0, 'content'); } ΔembeddedViewEnd(); } else { if (ΔembeddedViewStart(1, 1, 0)) { Δtext(0, 'else'); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 4, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
(else)
'); parent.value = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
(content)
'); parent.value = false; detectChanges(parent); expect(toHtml(parent)).toEqual('
(else)
'); }); it('should support projection into embedded views', () => { let childCmptInstance: any; /** *
* % if (!skipContent) { * * * * % } *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δcontainer(1); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(1); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 2, 0); if (rf0 & RenderFlags.Create) { ΔelementStart(0, 'span'); Δprojection(1); ΔelementEnd(); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 2, 0); /** * *
text
* content *
*/ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'div'); { Δtext(2, 'text'); } ΔelementEnd(); Δtext(3, 'content'); } ΔelementEnd(); // testing childCmptInstance = getDirectiveOnNode(0); } }, 4, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
text
content
'); childCmptInstance.skipContent = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
'); }); it('should support projection into embedded views when no projected nodes', () => { let childCmptInstance: any; /** *
* % if (!skipContent) { * * text * % } *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δcontainer(1); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(1); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 2, 0); if (rf0 & RenderFlags.Create) { Δprojection(0); Δtext(1, 'text'); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 2); /** */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { Δelement(0, 'child'); // testing childCmptInstance = getDirectiveOnNode(0); } }, 1, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
text
'); childCmptInstance.skipContent = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
'); }); it('should support projection into embedded views when ng-content is a root node of an embedded view', () => { let childCmptInstance: any; /** *
* % if (!skipContent) { * * % } *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δcontainer(1); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(1); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δprojection(0); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 2); /** * content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { childCmptInstance = getDirectiveOnNode(0); Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
content
'); childCmptInstance.skipContent = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
'); }); it('should project containers into containers', () => { /** *
* Before (inside) * % if (!skipContent) { * * % } * After (inside) *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δtext(1, 'Before (inside)-'); Δcontainer(2); Δtext(3, '-After (inside)'); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(2); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δprojection(0); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 4); /** * * Before text- * % if (!skipContent) { * content * % } * -After text * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, 'Before text-'); Δcontainer(2); Δtext(3, '-After text'); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(2); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δtext(0, 'content'); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 4, 0, [Child]); const fixture = new ComponentFixture(Parent); expect(fixture.html) .toEqual( '
Before (inside)-Before text-content-After text-After (inside)
'); fixture.component.skipContent = true; fixture.update(); expect(fixture.html) .toEqual( '
Before (inside)-Before text--After text-After (inside)
'); }); it('should re-project containers into containers', () => { /** *
* % if (!skipContent) { * * % } *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δcontainer(1); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(1); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δprojection(0); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 2); /** * * Before text * % if (!skipContent) { * * % } * -After text * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'child'); { Δtext(1, 'Before text'); Δcontainer(2); Δtext(3, '-After text'); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(2); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δprojection(0); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 4, 0, [Child]); let parent: any; /**

text

*/ const App = createComponent('app', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'parent'); { ΔelementStart(1, 'p'); { Δtext(2, 'text'); } ΔelementEnd(); } ΔelementEnd(); // testing parent = getDirectiveOnNode(0); } }, 3, 0, [Parent]); const fixture = new ComponentFixture(App); expect(fixture.html) .toEqual('
Before text

text

-After text
'); parent.skipContent = true; fixture.update(); expect(fixture.html) .toEqual('
Before text-After text
'); }); it('should support projection into embedded views when ng-content is a root node of an embedded view, with other nodes after', () => { let childCmptInstance: any; /** *
* % if (!skipContent) { * before--after * % } *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δcontainer(1); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(1); { if (!ctx.skipContent) { let rf0 = ΔembeddedViewStart(0, 3, 0); if (rf0 & RenderFlags.Create) { Δtext(0, 'before-'); Δprojection(1); Δtext(2, '-after'); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 2); /** * content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { childCmptInstance = getDirectiveOnNode(0); Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
before-content-after
'); childCmptInstance.skipContent = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
'); }); it('should project into dynamic views (with createEmbeddedView)', () => { /** * Before- * * * * -After */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δtext(0, 'Before-'); Δtemplate(1, IfTemplate, 1, 0, 'ng-template', [AttributeMarker.Bindings, 'ngIf']); Δtext(2, '-After'); } if (rf & RenderFlags.Update) { ΔelementProperty(1, 'ngIf', Δbind(ctx.showing)); } }, 3, 1, [NgIf]); function IfTemplate(rf1: RenderFlags, ctx: any) { if (rf1 & RenderFlags.Create) { Δprojection(0); } } let child: {showing: boolean}; /** * *
A
* Some text *
*/ const App = createComponent('app', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'div'); { Δtext(2, 'A'); } ΔelementEnd(); Δtext(3, 'Some text'); } ΔelementEnd(); // testing child = getDirectiveOnNode(0); } }, 4, 0, [Child]); const fixture = new ComponentFixture(App); child !.showing = true; fixture.update(); expect(fixture.html).toEqual('Before-
A
Some text-After
'); child !.showing = false; fixture.update(); expect(fixture.html).toEqual('Before--After'); child !.showing = true; fixture.update(); expect(fixture.html).toEqual('Before-
A
Some text-After
'); }); it('should project into dynamic views (with insertion)', () => { /** * Before- * * * * -After */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δtext(0, 'Before-'); Δtemplate(1, IfTemplate, 1, 0, 'ng-template', [AttributeMarker.Bindings, 'ngIf']); Δtext(2, '-After'); } if (rf & RenderFlags.Update) { ΔelementProperty(1, 'ngIf', Δbind(ctx.showing)); } }, 3, 1, [NgIf]); function IfTemplate(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { Δprojection(0); } } let child: {showing: boolean}; /** * *
A
* Some text *
*/ const App = createComponent('app', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'div'); { Δtext(2, 'A'); } ΔelementEnd(); Δtext(3, 'Some text'); } ΔelementEnd(); // testing child = getDirectiveOnNode(0); } }, 4, 0, [Child]); const fixture = new ComponentFixture(App); child !.showing = true; fixture.update(); expect(fixture.html).toEqual('Before-
A
Some text-After
'); child !.showing = false; fixture.update(); expect(fixture.html).toEqual('Before--After'); child !.showing = true; fixture.update(); expect(fixture.html).toEqual('Before-
A
Some text-After
'); }); it('should project into dynamic views with specific selectors', () => { /** * * Before- * * * * -After */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['div']]], ['div']); Δprojection(0); Δtext(1, 'Before-'); Δtemplate(2, IfTemplate, 1, 0, 'ng-template', [AttributeMarker.Bindings, 'ngIf']); Δtext(3, '-After'); } if (rf & RenderFlags.Update) { ΔelementProperty(2, 'ngIf', Δbind(ctx.showing)); } }, 4, 1, [NgIf]); function IfTemplate(rf1: RenderFlags) { if (rf1 & RenderFlags.Create) { Δprojection(0, 1); } } let child: {showing: boolean}; /** * *
A
* B *
*/ const App = createComponent('app', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'div'); { Δtext(2, 'A'); } ΔelementEnd(); ΔelementStart(3, 'span'); { Δtext(4, 'B'); } ΔelementEnd(); } ΔelementEnd(); // testing child = getDirectiveOnNode(0); } }, 5, 0, [Child]); const fixture = new ComponentFixture(App); child !.showing = true; fixture.update(); expect(fixture.html).toEqual('BBefore-
A
-After
'); child !.showing = false; fixture.update(); expect(fixture.html).toEqual('BBefore--After'); child !.showing = true; fixture.update(); expect(fixture.html).toEqual('BBefore-
A
-After
'); }); it('should project if is in a template that has different declaration/insertion points', () => { let triggerDir !: Trigger; function NgTemplate(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { Δprojection(0); } } /** * * * */ const Comp = createComponent( 'comp', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δtemplate(1, NgTemplate, 1, 0, 'ng-template', null, null, ΔtemplateRefExtractor); } }, 2, 0, [], [], function(rf: RenderFlags, ctx: any) { /** @ViewChild(TemplateRef) template: TemplateRef */ if (rf & RenderFlags.Create) { ΔviewQuery(TemplateRef as any, true, null); } if (rf & RenderFlags.Update) { let tmp: any; ΔqueryRefresh(tmp = ΔloadViewQuery>()) && (ctx.template = tmp.first); } }); class Trigger { // @Input() trigger: any; constructor(public vcr: ViewContainerRef) {} open() { this.vcr.createEmbeddedView(this.trigger.template); } static ngComponentDef = ΔdefineDirective({ type: Trigger, selectors: [['', 'trigger', '']], factory: () => triggerDir = new Trigger(ΔdirectiveInject(ViewContainerRef as any)), inputs: {trigger: 'trigger'} }); } /** * * * Some content * */ const App = createComponent('app', (rf: RenderFlags, ctx: any) => { if (rf & RenderFlags.Create) { Δelement(0, 'button', [AttributeMarker.Bindings, 'trigger']); ΔelementStart(1, 'comp', null, ['comp', '']); { Δtext(3, 'Some content'); } ΔelementEnd(); } if (rf & RenderFlags.Update) { const comp = Δreference(2); ΔelementProperty(0, 'trigger', Δbind(comp)); } }, 4, 1, [Comp, Trigger]); const fixture = new ComponentFixture(App); expect(fixture.html).toEqual(``); triggerDir.open(); expect(fixture.html).toEqual(`Some content`); }); it('should project nodes into the last ng-content', () => { /** *
* */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'div'); { Δprojection(1); } ΔelementEnd(); ΔelementStart(2, 'span'); { Δprojection(3); } ΔelementEnd(); } }, 4); /** * content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
content
'); }); /** * Warning: this test is _not_ in-line with what Angular does atm. * Moreover the current implementation logic will result in DOM nodes * being re-assigned from one parent to another. Proposal: have compiler * to remove all but the latest occurrence of so we generate * only one P(n, m, 0) instruction. It would make it consistent with the * current Angular behavior: * http://plnkr.co/edit/OAYkNawTDPkYBFTqovTP?p=preview */ it('should project nodes into the last available ng-content', () => { let childCmptInstance: any; /** * *
* % if (show) { * * % } *
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); ΔelementStart(1, 'div'); { Δcontainer(2); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔcontainerRefreshStart(2); { if (ctx.show) { let rf0 = ΔembeddedViewStart(0, 1, 0); if (rf0 & RenderFlags.Create) { Δprojection(0); } ΔembeddedViewEnd(); } } ΔcontainerRefreshEnd(); } }, 3); /** * content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { childCmptInstance = getDirectiveOnNode(0); Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('content
'); childCmptInstance.show = true; detectChanges(parent); expect(toHtml(parent)).toEqual('
content
'); }); // https://stackblitz.com/edit/angular-ceqmnw?file=src%2Fapp%2Fapp.component.ts it('should project nodes into the last ng-content unrolled by ngFor', () => { const items = [1, 2]; /**
({{index}}):
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); { Δtemplate(0, ForTemplate, 3, 1, 'div', [AttributeMarker.Template, 'ngFor', 'ngForOf']); } } if (rf & RenderFlags.Update) { ΔelementProperty(0, 'ngForOf', Δbind(items)); } }, 1, 1, [NgForOf]); function ForTemplate(rf1: RenderFlags, ctx: {index: number}) { if (rf1 & RenderFlags.Create) { ΔelementStart(0, 'div'); Δtext(1); Δprojection(2); ΔelementEnd(); } if (rf1 & RenderFlags.Update) { ΔtextBinding(1, Δinterpolation1('(', ctx.index, '):')); } } /** * content */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
(0):
(1):content
'); }); it('should project with multiple instances of a component with projection', () => { const ProjectionComp = createComponent('projection-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δtext(0, 'Before'); Δprojection(1); Δtext(2, 'After'); } }, 3); /** * *
A
*

123

*
* *
B
*

456

*
*/ const AppComp = createComponent('app-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'projection-comp'); { ΔelementStart(1, 'div'); { Δtext(2, 'A'); } ΔelementEnd(); ΔelementStart(3, 'p'); { Δtext(4, '123'); } ΔelementEnd(); } ΔelementEnd(); ΔelementStart(5, 'projection-comp'); { ΔelementStart(6, 'div'); { Δtext(7, 'B'); } ΔelementEnd(); ΔelementStart(8, 'p'); { Δtext(9, '456'); } ΔelementEnd(); } ΔelementEnd(); } }, 10, 0, [ProjectionComp]); const fixture = new ComponentFixture(AppComp); fixture.update(); expect(fixture.html) .toEqual( 'Before
A

123

After
' + 'Before
B

456

After
'); }); it('should re-project with multiple instances of a component with projection', () => { /** * Before * * After */ const ProjectionComp = createComponent('projection-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δtext(0, 'Before'); Δprojection(1); Δtext(2, 'After'); } }, 3); /** * *
A
* *

123

*
* *
B
*

456

*
*/ const ProjectionParent = createComponent('parent-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'projection-comp'); { ΔelementStart(1, 'div'); { Δtext(2, 'A'); } ΔelementEnd(); Δprojection(3, 0); ΔelementStart(4, 'p'); { Δtext(5, '123'); } ΔelementEnd(); } ΔelementEnd(); ΔelementStart(6, 'projection-comp'); { ΔelementStart(7, 'div'); { Δtext(8, 'B'); } ΔelementEnd(); ΔelementStart(9, 'p'); { Δtext(10, '456'); } ΔelementEnd(); } ΔelementEnd(); } }, 11, 0, [ProjectionComp]); /** * * **ABC** * * * **DEF** * */ const AppComp = createComponent('app-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'parent-comp'); { Δtext(1, '**ABC**'); } ΔelementEnd(); ΔelementStart(2, 'parent-comp'); { Δtext(3, '**DEF**'); } ΔelementEnd(); } }, 4, 0, [ProjectionParent]); const fixture = new ComponentFixture(AppComp); fixture.update(); expect(fixture.html) .toEqual( '' + 'Before
A
**ABC**

123

After
' + 'Before
B

456

After
' + '' + 'Before
A
**DEF**

123

After
' + 'Before
B

456

After
'); }); it('should project ng-container at the content root', () => { ``; const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); } }, 1); ` content `; const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementContainerStart(1); { ΔelementContainerStart(2); { Δtext(3, 'content'); } ΔelementContainerEnd(); } ΔelementContainerEnd(); } ΔelementEnd(); } }, 4, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('content'); }); it('should re-project ng-container at the content root', () => { ``; const GrandChild = createComponent('grand-child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); } }, 1); ` `; const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'grand-child'); { Δprojection(1); } ΔelementEnd(); } }, 2, 0, [GrandChild]); ` content `; const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementContainerStart(1); { ΔelementContainerStart(2); { Δtext(3, 'content'); } ΔelementContainerEnd(); } ΔelementContainerEnd(); } ΔelementEnd(); } }, 4, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('content'); }); it('should handle projected containers inside other containers', () => { //
Child content
const NestedComp = createComponent('nested-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'div'); Δtext(1, 'Child content'); ΔelementEnd(); } }, 2, 0, []); // const RootComp = createComponent('root-comp', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); Δprojection(0); } }, 1, 0, []); // // // // // function MyApp_ng_container_1_child_comp_1_Template(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { Δelement(0, 'nested-comp'); } } function MyApp_ng_container_1_Template(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementContainerStart(0); Δtemplate( 1, MyApp_ng_container_1_child_comp_1_Template, 1, 0, 'nested-comp', [AttributeMarker.Template, 'ngIf']); ΔelementContainerEnd(); } if (rf & RenderFlags.Update) { const last_r2 = ctx.last; ΔelementProperty(1, 'ngIf', Δbind(!last_r2)); } } let myAppInstance: MyApp; class MyApp { items = [1, 2]; static ngComponentDef = ΔdefineComponent({ type: MyApp, selectors: [['', 'my-app', '']], factory: () => myAppInstance = new MyApp(), consts: 2, vars: 1, template: function MyApp_Template(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'root-comp'); Δtemplate( 1, MyApp_ng_container_1_Template, 2, 1, 'ng-container', [AttributeMarker.Template, 'ngFor', 'ngForOf']); ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔelementProperty(1, 'ngForOf', Δbind(ctx.items)); } }, directives: [NgForOf, NgIf, NestedComp, RootComp] }); } const fixture = new ComponentFixture(MyApp); fixture.update(); // expecting # of divs to be (items.length - 1), since last element is filtered out by *ngIf, // this applies to all other assertions below expect(fixture.hostElement.querySelectorAll('div').length).toBe(1); myAppInstance !.items = [3, 4, 5]; fixture.update(); expect(fixture.hostElement.querySelectorAll('div').length).toBe(2); myAppInstance !.items = [6, 7, 8, 9]; fixture.update(); expect(fixture.hostElement.querySelectorAll('div').length).toBe(3); }); describe('with selectors', () => { it('should project nodes using attribute selectors', () => { /** *
*
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef( [[['span', 'title', 'toFirst']], [['span', 'title', 'toSecond']]], ['span[title=toFirst]', 'span[title=toSecond]']); ΔelementStart(0, 'div', ['id', 'first']); { Δprojection(1, 1); } ΔelementEnd(); ΔelementStart(2, 'div', ['id', 'second']); { Δprojection(3, 2); } ΔelementEnd(); } }, 4); /** * * 1 * 2 * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span', ['title', 'toFirst']); { Δtext(2, '1'); } ΔelementEnd(); ΔelementStart(3, 'span', ['title', 'toSecond']); { Δtext(4, '2'); } ΔelementEnd(); } ΔelementEnd(); } }, 5, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '
1
2
'); }); // https://stackblitz.com/edit/angular-psokum?file=src%2Fapp%2Fapp.module.ts it('should project nodes where attribute selector matches a binding', () => { /** * */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['', 'title', '']]], ['[title]']); { Δprojection(0, 1); } } }, 1); /** * * Has title * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span', [AttributeMarker.Bindings, 'title']); { Δtext(2, 'Has title'); } ΔelementEnd(); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔelementProperty(1, 'title', Δbind('Some title')); } }, 3, 1, [Child]); const fixture = new ComponentFixture(Parent); expect(fixture.html).toEqual('Has title'); }); it('should project nodes using class selectors', () => { /** *
*
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef( [ [['span', SelectorFlags.CLASS, 'toFirst']], [['span', SelectorFlags.CLASS, 'toSecond']] ], ['span.toFirst', 'span.toSecond']); ΔelementStart(0, 'div', ['id', 'first']); { Δprojection(1, 1); } ΔelementEnd(); ΔelementStart(2, 'div', ['id', 'second']); { Δprojection(3, 2); } ΔelementEnd(); } }, 4); /** * * 1 * 2 * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span', ['class', 'toFirst']); { Δtext(2, '1'); } ΔelementEnd(); ΔelementStart(3, 'span', ['class', 'toSecond']); { Δtext(4, '2'); } ΔelementEnd(); } ΔelementEnd(); } }, 5, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '
1
2
'); }); it('should project nodes using class selectors when element has multiple classes', () => { /** *
*
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef( [ [['span', SelectorFlags.CLASS, 'toFirst']], [['span', SelectorFlags.CLASS, 'toSecond']] ], ['span.toFirst', 'span.toSecond']); ΔelementStart(0, 'div', ['id', 'first']); { Δprojection(1, 1); } ΔelementEnd(); ΔelementStart(2, 'div', ['id', 'second']); { Δprojection(3, 2); } ΔelementEnd(); } }, 4); /** * * 1 * 2 * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span', ['class', 'other toFirst']); { Δtext(2, '1'); } ΔelementEnd(); ΔelementStart(3, 'span', ['class', 'toSecond noise']); { Δtext(4, '2'); } ΔelementEnd(); } ΔelementEnd(); } }, 5, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '
1
2
'); }); it('should project nodes into the first matching selector', () => { /** *
*
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef( [[['span']], [['span', SelectorFlags.CLASS, 'toSecond']]], ['span', 'span.toSecond']); ΔelementStart(0, 'div', ['id', 'first']); { Δprojection(1, 1); } ΔelementEnd(); ΔelementStart(2, 'div', ['id', 'second']); { Δprojection(3, 2); } ΔelementEnd(); } }, 4); /** * * 1 * 2 * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span', ['class', 'toFirst']); { Δtext(2, '1'); } ΔelementEnd(); ΔelementStart(3, 'span', ['class', 'toSecond']); { Δtext(4, '2'); } ΔelementEnd(); } ΔelementEnd(); } }, 5, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '
12
'); }); it('should allow mixing ng-content with and without selectors', () => { /** *
*
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['span', SelectorFlags.CLASS, 'toFirst']]], ['span.toFirst']); ΔelementStart(0, 'div', ['id', 'first']); { Δprojection(1, 1); } ΔelementEnd(); ΔelementStart(2, 'div', ['id', 'second']); { Δprojection(3); } ΔelementEnd(); } }, 4); /** * * 1 * 2 * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span', ['class', 'toFirst']); { Δtext(2, '1'); } ΔelementEnd(); ΔelementStart(3, 'span'); { Δtext(4, 'remaining'); } ΔelementEnd(); Δtext(5, 'more remaining'); } ΔelementEnd(); } }, 6, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '
1
remainingmore remaining
'); }); it('should allow mixing ng-content with and without selectors - ng-content first', () => { /** *
*
*/ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['span', SelectorFlags.CLASS, 'toSecond']]], ['span.toSecond']); ΔelementStart(0, 'div', ['id', 'first']); { Δprojection(1); } ΔelementEnd(); ΔelementStart(2, 'div', ['id', 'second']); { Δprojection(3, 1); } ΔelementEnd(); } }, 4); /** * * 1 * 2 * remaining * */ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span'); { Δtext(2, '1'); } ΔelementEnd(); ΔelementStart(3, 'span', ['class', 'toSecond']); { Δtext(4, '2'); } ΔelementEnd(); Δtext(5, 'remaining'); } ΔelementEnd(); } }, 6, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( '
1remaining
2
'); }); /** * Descending into projected content for selector-matching purposes is not supported * today: http://plnkr.co/edit/MYQcNfHSTKp9KvbzJWVQ?p=preview */ it('should not descend into re-projected content', () => { /** * *
* */ const GrandChild = createComponent('grand-child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['span']]], ['span']); Δprojection(0, 1); Δelement(1, 'hr'); Δprojection(2); } }, 3); /** * * * in child template * */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'grand-child'); { Δprojection(1); ΔelementStart(2, 'span'); { Δtext(3, 'in child template'); } ΔelementEnd(); } ΔelementEnd(); } }, 4, 0, [GrandChild]); /** * *
* parent content *
*
*/ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'span'); { Δtext(2, 'parent content'); } ΔelementEnd(); } ΔelementEnd(); } }, 3, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)) .toEqual( 'in child template
parent content
'); }); it('should match selectors on ng-content nodes with attributes', () => { /** * *
* */ const Card = createComponent('card', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef( [[['', 'card-title', '']], [['', 'card-content', '']]], ['[card-title]', '[card-content]']); Δprojection(0, 1); Δelement(1, 'hr'); Δprojection(2, 2); } }, 3); /** * *

Title

* *
*/ const CardWithTitle = createComponent('card-with-title', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'card'); { ΔelementStart(1, 'h1', ['card-title', '']); { Δtext(2, 'Title'); } ΔelementEnd(); Δprojection(3, 0, ['card-content', '']); } ΔelementEnd(); } }, 4, 0, [Card]); /** * * content * */ const App = createComponent('app', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'card-with-title'); { Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [CardWithTitle]); const app = renderComponent(App); expect(toHtml(app)) .toEqual( '

Title


content
'); }); it('should support ngProjectAs on elements (including )', () => { /** * *
* */ const Card = createComponent('card', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef( [[['', 'card-title', '']], [['', 'card-content', '']]], ['[card-title]', '[card-content]']); Δprojection(0, 1); Δelement(1, 'hr'); Δprojection(2, 2); } }, 3); /** * *

* */ const CardWithTitle = createComponent('card-with-title', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef(); ΔelementStart(0, 'card'); { ΔelementStart(1, 'h1', ['ngProjectAs', '[card-title]']); { Δtext(2, 'Title'); } ΔelementEnd(); Δprojection(3, 0, ['ngProjectAs', '[card-content]']); } ΔelementEnd(); } }, 4, 0, [Card]); /** * * content * */ const App = createComponent('app', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'card-with-title'); { Δtext(1, 'content'); } ΔelementEnd(); } }, 2, 0, [CardWithTitle]); const app = renderComponent(App); expect(toHtml(app)) .toEqual('

Title


content
'); }); it('should not match selectors against node having ngProjectAs attribute', function() { /** * */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['div']]], ['div']); Δprojection(0, 1); } }, 1); /** * *
should not project
*
should project
*
*/ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { ΔelementStart(1, 'div', ['ngProjectAs', 'span']); { Δtext(2, 'should not project'); } ΔelementEnd(); ΔelementStart(3, 'div'); { Δtext(4, 'should project'); } ΔelementEnd(); } ΔelementEnd(); } }, 5, 0, [Child]); const parent = renderComponent(Parent); expect(toHtml(parent)).toEqual('
should project
'); }); it('should match selectors against projected containers', () => { /** * * * */ const Child = createComponent('child', function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔprojectionDef([[['div']]], ['div']); ΔelementStart(0, 'span'); { Δprojection(1, 1); } ΔelementEnd(); } }, 2); function IfTemplate(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'div'); { Δtext(1, 'content'); } ΔelementEnd(); } } /** * *
content
*
*/ const Parent = createComponent('parent', function(rf: RenderFlags, ctx: {value: any}) { if (rf & RenderFlags.Create) { ΔelementStart(0, 'child'); { Δtemplate(1, IfTemplate, 2, 0, 'div', [AttributeMarker.Template, 'ngIf']); } ΔelementEnd(); } if (rf & RenderFlags.Update) { ΔelementProperty(1, 'ngIf', Δbind(ctx.value)); } }, 2, 1, [Child, NgIf]); const fixture = new ComponentFixture(Parent); fixture.component.value = true; fixture.update(); expect(fixture.html).toEqual('
content
'); }); }); });