fix(query): set fixed @ViewChild
/ @ContentChild
right after the view is created
This is needed to have a true replacement of the previous `DynamicComponentLoader.loadNextToLocation`, so that components can be loaded into the view before change detection runs. Closes #9040
This commit is contained in:
@ -135,6 +135,28 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should set static view and content children already after the constructor call',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
var template =
|
||||
'<needs-static-content-view-child #q><div text="contentFoo"></div></needs-static-content-view-child>';
|
||||
|
||||
tcb.overrideTemplate(MyComp0, template)
|
||||
.createAsync(MyComp0)
|
||||
.then((view) => {
|
||||
var q: NeedsStaticContentAndViewChild =
|
||||
view.debugElement.children[0].references['q'];
|
||||
expect(q.contentChild.text).toBeFalsy();
|
||||
expect(q.viewChild.text).toBeFalsy();
|
||||
|
||||
view.detectChanges();
|
||||
|
||||
expect(q.contentChild.text).toEqual('contentFoo');
|
||||
expect(q.viewChild.text).toEqual('viewFoo');
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should contain the first view child accross embedded views',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
var template = '<needs-view-child #q></needs-view-child>';
|
||||
@ -882,6 +904,19 @@ class NeedsViewChild implements AfterViewInit,
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'needs-static-content-view-child',
|
||||
template: `
|
||||
<div text="viewFoo"></div>
|
||||
`,
|
||||
directives: [TextDirective]
|
||||
})
|
||||
class NeedsStaticContentAndViewChild {
|
||||
@ContentChild(TextDirective) contentChild: TextDirective;
|
||||
|
||||
@ViewChild(TextDirective) viewChild: TextDirective;
|
||||
}
|
||||
|
||||
@Directive({selector: '[dir]'})
|
||||
@Injectable()
|
||||
class InertDirective {
|
||||
@ -1119,6 +1154,7 @@ class HasNullQueryCondition {
|
||||
NeedsContentChildren,
|
||||
NeedsViewChildren,
|
||||
NeedsViewChild,
|
||||
NeedsStaticContentAndViewChild,
|
||||
NeedsContentChild,
|
||||
NeedsTpl,
|
||||
NeedsNamedTpl,
|
||||
|
Reference in New Issue
Block a user