diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 8b0e0dd834..a797e24c46 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -1292,8 +1292,9 @@ export function componentRefresh(adjustedElementIndex: number): void { const hostView = getComponentViewByIndex(adjustedElementIndex, lView); ngDevMode && assertNodeType(lView[TVIEW].data[adjustedElementIndex] as TNode, TNodeType.Element); - // Only attached CheckAlways components or attached, dirty OnPush components should be checked - if (viewAttachedToChangeDetector(hostView) && + // Only components in creation mode, attached CheckAlways + // components or attached, dirty OnPush components should be checked + if ((viewAttachedToChangeDetector(hostView) || isCreationMode(lView)) && hostView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty)) { syncViewWithBlueprint(hostView); checkView(hostView, hostView[CONTEXT]); diff --git a/packages/core/test/acceptance/content_spec.ts b/packages/core/test/acceptance/content_spec.ts index 63b6348431..e73279837f 100644 --- a/packages/core/test/acceptance/content_spec.ts +++ b/packages/core/test/acceptance/content_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Component, Directive} from '@angular/core'; +import {ChangeDetectorRef, Component, Directive} from '@angular/core'; import {TestBed} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/src/matchers'; @@ -57,6 +57,30 @@ describe('projection', () => { expect(fixture.nativeElement).toHaveText('6|7|8|'); }); + it('should project content if the change detector has been detached', () => { + @Component({selector: 'my-comp', template: ''}) + class MyComp { + constructor(changeDetectorRef: ChangeDetectorRef) { changeDetectorRef.detach(); } + } + + @Component({ + selector: 'my-app', + template: ` + +

hello

+
+ ` + }) + class MyApp { + } + + TestBed.configureTestingModule({declarations: [MyComp, MyApp]}); + const fixture = TestBed.createComponent(MyApp); + fixture.detectChanges(); + + expect(fixture.nativeElement).toHaveText('hello'); + }); + describe('on inline templates (e.g. *ngIf)', () => { it('should work when matching the element name', () => { let divDirectives = 0;