X Tutup
Skip to content

Commit 1f7a41c

Browse files
tboschalexeagle
authored andcommitted
fix(query): update view queries that query directives in embedded views
Fixes #6747
1 parent f4f614f commit 1f7a41c

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

modules/angular2/src/core/linker/element.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,11 @@ export class AppElement implements DependencyProvider, ElementRef, AfterViewChec
463463
var inj: AppElement = this;
464464
while (isPresent(inj)) {
465465
inj._setQueriesAsDirty();
466-
inj = inj.parent;
466+
if (isBlank(inj.parent) && isPresent(inj.parentView.containerAppElement)) {
467+
inj = inj.parentView.containerAppElement;
468+
} else {
469+
inj = inj.parent;
470+
}
467471
}
468472
}
469473

modules/angular2/test/core/linker/query_integration_spec.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,35 @@ export function main() {
140140
});
141141
}));
142142

143+
it('should contain the first view child accross embedded views',
144+
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
145+
var template = '<needs-view-child #q></needs-view-child>';
146+
tcb.overrideTemplate(MyComp, template)
147+
.overrideTemplate(
148+
NeedsViewChild,
149+
'<div *ngIf="true"><div *ngIf="shouldShow" text="foo"></div></div>')
150+
.createAsync(MyComp)
151+
.then((view) => {
152+
view.detectChanges();
153+
var q = view.debugElement.componentViewChildren[0].getLocal('q');
154+
155+
expect(q.log).toEqual([["setter", "foo"], ["init", "foo"], ["check", "foo"]]);
156+
157+
q.shouldShow = false;
158+
view.detectChanges();
159+
160+
expect(q.log).toEqual([
161+
["setter", "foo"],
162+
["init", "foo"],
163+
["check", "foo"],
164+
["setter", null],
165+
["check", null]
166+
]);
167+
168+
async.done();
169+
});
170+
}));
171+
143172
it('should contain all directives in the light dom when descendants flag is used',
144173
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
145174
var template = '<div text="1"></div>' +
@@ -741,7 +770,6 @@ class NeedsViewChild implements AfterViewInit,
741770
ngAfterViewChecked() { this.log.push(["check", isPresent(this.child) ? this.child.text : null]); }
742771
}
743772

744-
745773
@Directive({selector: '[dir]'})
746774
@Injectable()
747775
class InertDirective {

0 commit comments

Comments
 (0)
X Tutup