refactor(ivy): ViewRef needs embededViewRef declaration (#33074)
PR Close #33074
This commit is contained in:

committed by
Kara Erickson

parent
f1ffd57105
commit
5632424d04
@ -11,6 +11,7 @@ import {CommonModule} from '@angular/common';
|
||||
import {ApplicationRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactoryResolver, ComponentRef, Directive, DoCheck, EmbeddedViewRef, ErrorHandler, Input, NgModule, OnInit, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
|
||||
describe('change detection', () => {
|
||||
|
||||
@ -913,6 +914,41 @@ describe('change detection', () => {
|
||||
expect(fixture.nativeElement.textContent).toEqual('two - two');
|
||||
});
|
||||
|
||||
it('async pipe should trigger CD for embedded views where the declaration and insertion views are different',
|
||||
() => {
|
||||
@Component({
|
||||
selector: 'insertion',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: ` <ng-container [ngTemplateOutlet]="template"> </ng-container> `
|
||||
})
|
||||
class Insertion {
|
||||
@Input() template !: TemplateRef<{}>;
|
||||
}
|
||||
|
||||
// This component uses async pipe (which calls markForCheck) in a view that has different
|
||||
// insertion and declaration views.
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<insertion [template]="ref"></insertion>
|
||||
<ng-template #ref>
|
||||
<span>{{value | async}}</span>
|
||||
</ng-template>
|
||||
`
|
||||
})
|
||||
class Declaration {
|
||||
value = new BehaviorSubject('initial value');
|
||||
}
|
||||
|
||||
const fixture = TestBed.configureTestingModule({declarations: [Insertion, Declaration]})
|
||||
.createComponent(Declaration);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.textContent).toContain('initial value');
|
||||
fixture.componentInstance.value.next('new value');
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.textContent).toContain('new value');
|
||||
});
|
||||
|
||||
// TODO(kara): add test for dynamic views once bug fix is in
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user