feat(query): view query is properly updated when dom changes.
Fixes a bug in view manager util where sibling injector is not correctly calculated. ViewQuery no longer includes the view's initiating component injector. Includes some refactoring of view methods and a removal of a polymorphic map call. Closes #3033 Closes #3439
This commit is contained in:
@ -355,7 +355,7 @@ export function main() {
|
||||
|
||||
view.detectChanges();
|
||||
|
||||
expect(q.query.map((d: TextDirective) => d.text)).toEqual(["self", "1", "2", "3"]);
|
||||
expect(q.query.map((d: TextDirective) => d.text)).toEqual(["1", "2", "3"]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
@ -407,26 +407,29 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
/* TODO(rado): fix and reenable.
|
||||
|
||||
it('should maintain directives in pre-order depth-first DOM order after dynamic insertion',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb:TestComponentBuilder, async) => {
|
||||
var template = '<needs-view-query-order #q text="self"></needs-view-query-order>';
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
var template = '<needs-view-query-order #q></needs-view-query-order>';
|
||||
|
||||
tcb.overrideTemplate(MyComp, template)
|
||||
.createAsync(MyComp)
|
||||
.then((view) => {
|
||||
var q:NeedsViewQueryOrder = view.componentViewChildren[0].getLocal("q");
|
||||
tcb.overrideTemplate(MyComp, template)
|
||||
.createAsync(MyComp)
|
||||
.then((view) => {
|
||||
var q: NeedsViewQueryOrder = view.componentViewChildren[0].getLocal("q");
|
||||
|
||||
view.detectChanges();
|
||||
view.detectChanges();
|
||||
|
||||
expect(q.query.length).toBe(4);
|
||||
expect(q.query.first.text).toEqual("1");
|
||||
expect(q.query.first.text).toEqual("4");
|
||||
expect(q.query.map((d: TextDirective) => d.text)).toEqual(["1", "2", "3", "4"]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));*/
|
||||
q.list = ["-3", "2"];
|
||||
view.detectChanges();
|
||||
|
||||
|
||||
expect(q.query.map((d: TextDirective) => d.text)).toEqual(["1", "-3", "2", "4"]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -551,17 +554,23 @@ class NeedsViewQueryNestedIf {
|
||||
}
|
||||
|
||||
|
||||
// TODO(rado): once https://github.com/angular/angular/issues/3438 is resolved
|
||||
// duplicate the test without InertDirective.
|
||||
@Component({selector: 'needs-view-query-order'})
|
||||
@View({
|
||||
directives: [NgFor, TextDirective],
|
||||
template: '<div text="1">' +
|
||||
'<div *ng-for="var i of [\'2\', \'3\']" [text]="i"></div>' +
|
||||
'<div text="4">'
|
||||
directives: [NgFor, TextDirective, InertDirective],
|
||||
template: '<div dir><div text="1"></div>' +
|
||||
'<div *ng-for="var i of list" [text]="i"></div>' +
|
||||
'<div text="4"></div></div>'
|
||||
})
|
||||
@Injectable()
|
||||
class NeedsViewQueryOrder {
|
||||
query: QueryList<TextDirective>;
|
||||
constructor(@ViewQuery(TextDirective) query: QueryList<TextDirective>) { this.query = query; }
|
||||
list: string[];
|
||||
constructor(@ViewQuery(TextDirective, {descendants: true}) query: QueryList<TextDirective>) {
|
||||
this.query = query;
|
||||
this.list = ['2', '3'];
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-tpl'})
|
||||
|
@ -171,7 +171,8 @@ export function main() {
|
||||
createViews(2);
|
||||
utils.attachViewInContainer(parentView, 0, contextView, 1, 0, childView);
|
||||
expect(childView.rootElementInjectors[0].spy('linkAfter'))
|
||||
.toHaveBeenCalledWith(contextView.elementInjectors[0], null);
|
||||
.toHaveBeenCalledWith(contextView.elementInjectors[0],
|
||||
contextView.elementInjectors[1]);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user