fix(query): update view queries that query directives in embedded views

Fixes #6747
This commit is contained in:
Tobias Bosch 2016-01-28 12:22:04 -08:00 committed by Alex Eagle
parent f4f614f3a9
commit 1f7a41c963
2 changed files with 34 additions and 2 deletions

View File

@ -463,9 +463,13 @@ export class AppElement implements DependencyProvider, ElementRef, AfterViewChec
var inj: AppElement = this;
while (isPresent(inj)) {
inj._setQueriesAsDirty();
if (isBlank(inj.parent) && isPresent(inj.parentView.containerAppElement)) {
inj = inj.parentView.containerAppElement;
} else {
inj = inj.parent;
}
}
}
private _setQueriesAsDirty(): void {
if (isPresent(this._queryStrategy)) {

View File

@ -140,6 +140,35 @@ export function main() {
});
}));
it('should contain the first view child accross embedded views',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<needs-view-child #q></needs-view-child>';
tcb.overrideTemplate(MyComp, template)
.overrideTemplate(
NeedsViewChild,
'<div *ngIf="true"><div *ngIf="shouldShow" text="foo"></div></div>')
.createAsync(MyComp)
.then((view) => {
view.detectChanges();
var q = view.debugElement.componentViewChildren[0].getLocal('q');
expect(q.log).toEqual([["setter", "foo"], ["init", "foo"], ["check", "foo"]]);
q.shouldShow = false;
view.detectChanges();
expect(q.log).toEqual([
["setter", "foo"],
["init", "foo"],
["check", "foo"],
["setter", null],
["check", null]
]);
async.done();
});
}));
it('should contain all directives in the light dom when descendants flag is used',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div text="1"></div>' +
@ -741,7 +770,6 @@ class NeedsViewChild implements AfterViewInit,
ngAfterViewChecked() { this.log.push(["check", isPresent(this.child) ? this.child.text : null]); }
}
@Directive({selector: '[dir]'})
@Injectable()
class InertDirective {