fix(query): do not visit dehydrated injectors.

This commit is contained in:
Rado Kirov 2015-08-14 16:02:50 -07:00 committed by Igor Minar
parent 4845583dcf
commit 6c9e712c34
2 changed files with 21 additions and 3 deletions

View File

@ -486,11 +486,11 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
this._addDirectivesToQueries();
this._addVarBindingsToQueries();
this.hydrated = true;
// TODO(rado): optimize this call, if view queries are not moved around,
// simply appending to the query list is faster than updating.
this._updateViewQueries();
this.hydrated = true;
}
private _updateViewQueries() {
@ -1164,7 +1164,7 @@ export class QueryRef {
}
visit(inj: ElementInjector, aggregator: any[]): void {
if (isBlank(inj) || !inj._hasQuery(this)) return;
if (isBlank(inj) || !inj._hasQuery(this) || !inj.hydrated) return;
if (this.query.isVarBindingQuery) {
this._aggregateVariableBindings(inj, aggregator);

View File

@ -103,6 +103,24 @@ export function main() {
});
}));
it('should be cleanly destroyed when a query crosses view boundaries',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template =
'<div text="1"></div>' +
'<needs-query text="2"><div *ng-if="shouldShow" [text]="\'3\'"></div></needs-query>' +
'<div text="4"></div>';
tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp)
.then((rtc) => {
rtc.componentInstance.shouldShow = true;
rtc.detectChanges();
rtc.destroy();
async.done();
});
}));
it('should reflect moved directives',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template =