diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 31e66f4368..65690c1aae 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -789,8 +789,10 @@ export class ElementInjector extends TreeNode implements Depend } this.remove(); - - ListWrapper.forEach(queriesToUpdate, (q) => q.update()); + // TODO(rado): update should work on view queries too, however currently it + // is not implemented, so we filter to non-view queries. + var nonViewQueries = ListWrapper.filter(queriesToUpdate, (q) => !q.query.isViewQuery); + ListWrapper.forEach(nonViewQueries, (q) => q.update()); } private _pruneQueryFromTree(query: QueryRef): void { diff --git a/modules/angular2/test/core/compiler/query_integration_spec.ts b/modules/angular2/test/core/compiler/query_integration_spec.ts index 0467d3ec05..76d25a4cdc 100644 --- a/modules/angular2/test/core/compiler/query_integration_spec.ts +++ b/modules/angular2/test/core/compiler/query_integration_spec.ts @@ -365,6 +365,30 @@ export function main() { }); })); + it('should not be affected by other changes in the component', + inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { + var template = ''; + + tcb.overrideTemplate(MyComp, template) + .createAsync(MyComp) + .then((view) => { + var q: NeedsViewQueryNestedIf = view.componentViewChildren[0].getLocal("q"); + + view.detectChanges(); + + expect(q.query.length).toEqual(1); + expect(q.query.first.text).toEqual("1"); + + q.show = false; + view.detectChanges(); + + expect(q.query.length).toEqual(1); + expect(q.query.first.text).toEqual("1"); + + async.done(); + }); + })); + /* TODO(rado): fix and reenable. it('should maintain directives in pre-order depth-first DOM order after dynamic insertion', @@ -396,6 +420,12 @@ class TextDirective { constructor() {} } +@Directive({selector: '[dir]'}) +@Injectable() +class InertDirective { + constructor() {} +} + @Component({selector: 'needs-query'}) @View({ directives: [NgFor, TextDirective], @@ -487,6 +517,22 @@ class NeedsViewQueryIf { } +@Component({selector: 'needs-view-query-nested-if'}) +@View({ + directives: [NgIf, InertDirective, TextDirective], + template: '
' +}) +@Injectable() +class NeedsViewQueryNestedIf { + show: boolean; + query: QueryList; + constructor(@ViewQuery(TextDirective) query: QueryList) { + this.query = query; + this.show = true; + } +} + + @Component({selector: 'needs-view-query-order'}) @View({ directives: [NgFor, TextDirective], @@ -511,8 +557,10 @@ class NeedsViewQueryOrder { NeedsViewQuery, NeedsViewQueryDesc, NeedsViewQueryIf, + NeedsViewQueryNestedIf, NeedsViewQueryOrder, TextDirective, + InertDirective, NgIf, NgFor ]