fix(query): view query should not be updated when subviews are attached.
This commit is contained in:
parent
c1ee943533
commit
34acef58e7
|
@ -789,8 +789,10 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||||
}
|
}
|
||||||
|
|
||||||
this.remove();
|
this.remove();
|
||||||
|
// TODO(rado): update should work on view queries too, however currently it
|
||||||
ListWrapper.forEach(queriesToUpdate, (q) => q.update());
|
// 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 {
|
private _pruneQueryFromTree(query: QueryRef): void {
|
||||||
|
|
|
@ -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 = '<needs-view-query-nested-if #q></needs-view-query-nested-if>';
|
||||||
|
|
||||||
|
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.
|
/* TODO(rado): fix and reenable.
|
||||||
|
|
||||||
it('should maintain directives in pre-order depth-first DOM order after dynamic insertion',
|
it('should maintain directives in pre-order depth-first DOM order after dynamic insertion',
|
||||||
|
@ -396,6 +420,12 @@ class TextDirective {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Directive({selector: '[dir]'})
|
||||||
|
@Injectable()
|
||||||
|
class InertDirective {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
@Component({selector: 'needs-query'})
|
@Component({selector: 'needs-query'})
|
||||||
@View({
|
@View({
|
||||||
directives: [NgFor, TextDirective],
|
directives: [NgFor, TextDirective],
|
||||||
|
@ -487,6 +517,22 @@ class NeedsViewQueryIf {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component({selector: 'needs-view-query-nested-if'})
|
||||||
|
@View({
|
||||||
|
directives: [NgIf, InertDirective, TextDirective],
|
||||||
|
template: '<div text="1"><div *ng-if="show"><div dir></div></div></div>'
|
||||||
|
})
|
||||||
|
@Injectable()
|
||||||
|
class NeedsViewQueryNestedIf {
|
||||||
|
show: boolean;
|
||||||
|
query: QueryList<TextDirective>;
|
||||||
|
constructor(@ViewQuery(TextDirective) query: QueryList<TextDirective>) {
|
||||||
|
this.query = query;
|
||||||
|
this.show = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component({selector: 'needs-view-query-order'})
|
@Component({selector: 'needs-view-query-order'})
|
||||||
@View({
|
@View({
|
||||||
directives: [NgFor, TextDirective],
|
directives: [NgFor, TextDirective],
|
||||||
|
@ -511,8 +557,10 @@ class NeedsViewQueryOrder {
|
||||||
NeedsViewQuery,
|
NeedsViewQuery,
|
||||||
NeedsViewQueryDesc,
|
NeedsViewQueryDesc,
|
||||||
NeedsViewQueryIf,
|
NeedsViewQueryIf,
|
||||||
|
NeedsViewQueryNestedIf,
|
||||||
NeedsViewQueryOrder,
|
NeedsViewQueryOrder,
|
||||||
TextDirective,
|
TextDirective,
|
||||||
|
InertDirective,
|
||||||
NgIf,
|
NgIf,
|
||||||
NgFor
|
NgFor
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue