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:
@ -53,7 +53,11 @@ export class CompileQuery {
|
||||
}
|
||||
}
|
||||
|
||||
afterChildren(targetMethod: CompileMethod) {
|
||||
private _isStatic(): boolean {
|
||||
return !this._values.values.some(value => value instanceof ViewQueryValues);
|
||||
}
|
||||
|
||||
afterChildren(targetStaticMethod, targetDynamicMethod: CompileMethod) {
|
||||
var values = createQueryValues(this._values);
|
||||
var updateStmts = [this.queryList.callMethod('reset', [o.literalArr(values)]).toStmt()];
|
||||
if (isPresent(this.ownerDirectiveExpression)) {
|
||||
@ -64,7 +68,15 @@ export class CompileQuery {
|
||||
if (!this.meta.first) {
|
||||
updateStmts.push(this.queryList.callMethod('notifyOnChanges', []).toStmt());
|
||||
}
|
||||
targetMethod.addStmt(new o.IfStmt(this.queryList.prop('dirty'), updateStmts));
|
||||
if (this.meta.first && this._isStatic()) {
|
||||
// for queries that don't change and the user asked for a single element,
|
||||
// set it immediately. That is e.g. needed for querying for ViewContainerRefs, ...
|
||||
// we don't do this for QueryLists for now as this would break the timing when
|
||||
// we call QueryList listeners...
|
||||
targetStaticMethod.addStmts(updateStmts);
|
||||
} else {
|
||||
targetDynamicMethod.addStmt(new o.IfStmt(this.queryList.prop('dirty'), updateStmts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user