X Tutup
Skip to content

Commit 6c9e712

Browse files
rkirovIgorMinar
authored andcommitted
fix(query): do not visit dehydrated injectors.
1 parent 4845583 commit 6c9e712

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,11 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
486486
this._addDirectivesToQueries();
487487
this._addVarBindingsToQueries();
488488

489+
this.hydrated = true;
490+
489491
// TODO(rado): optimize this call, if view queries are not moved around,
490492
// simply appending to the query list is faster than updating.
491493
this._updateViewQueries();
492-
493-
this.hydrated = true;
494494
}
495495

496496
private _updateViewQueries() {
@@ -1164,7 +1164,7 @@ export class QueryRef {
11641164
}
11651165

11661166
visit(inj: ElementInjector, aggregator: any[]): void {
1167-
if (isBlank(inj) || !inj._hasQuery(this)) return;
1167+
if (isBlank(inj) || !inj._hasQuery(this) || !inj.hydrated) return;
11681168

11691169
if (this.query.isVarBindingQuery) {
11701170
this._aggregateVariableBindings(inj, aggregator);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ export function main() {
103103
});
104104
}));
105105

106+
it('should be cleanly destroyed when a query crosses view boundaries',
107+
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
108+
var template =
109+
'<div text="1"></div>' +
110+
'<needs-query text="2"><div *ng-if="shouldShow" [text]="\'3\'"></div></needs-query>' +
111+
'<div text="4"></div>';
112+
113+
tcb.overrideTemplate(MyComp, template)
114+
.createAsync(MyComp)
115+
.then((rtc) => {
116+
rtc.componentInstance.shouldShow = true;
117+
rtc.detectChanges();
118+
rtc.destroy();
119+
120+
async.done();
121+
});
122+
}));
123+
106124
it('should reflect moved directives',
107125
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
108126
var template =

0 commit comments

Comments
 (0)
X Tutup