fix(ivy): pass ngContentSelectors through to defineComponent()
calls (#27867)
Libraries that create components dynamically using component factories, such as `@angular/upgrade` need to pass blocks of projected content through to the `ComponentFactory.create()` method. These blocks are extracted from the content by matching CSS selectors defined in `<ng-content select="..">` tags found in the component's template. The Angular compiler collects these CSS selectors when compiling a component's template, and exposes them via the `ComponentFactory.ngContentSelectors` property. This change ensures that this property is filled correctly when the component factory is created by compiling a component with the Ivy engine. PR Close #27867
This commit is contained in:

committed by
Andrew Kushnir

parent
e8a57f0ee6
commit
feebe03523
@ -264,6 +264,13 @@ export function compileComponentFromMetadata(
|
||||
|
||||
const templateFunctionExpression = templateBuilder.buildTemplateFunction(template.nodes, []);
|
||||
|
||||
// We need to provide this so that dynamically generated components know what
|
||||
// projected content blocks to pass through to the component when it is instantiated.
|
||||
const ngContentSelectors = templateBuilder.getNgContentSelectors();
|
||||
if (ngContentSelectors) {
|
||||
definitionMap.set('ngContentSelectors', ngContentSelectors);
|
||||
}
|
||||
|
||||
// e.g. `consts: 2`
|
||||
definitionMap.set('consts', o.literal(templateBuilder.getConstCount()));
|
||||
|
||||
|
@ -915,6 +915,12 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
|
||||
getVarCount() { return this._pureFunctionSlots; }
|
||||
|
||||
getNgContentSelectors(): o.Expression|null {
|
||||
return this._hasNgContent ?
|
||||
this.constantPool.getConstLiteral(asLiteral(this._ngContentSelectors), true) :
|
||||
null;
|
||||
}
|
||||
|
||||
private bindingContext() { return `${this._bindingContext++}`; }
|
||||
|
||||
// Bindings must only be resolved after all local refs have been visited, so all
|
||||
|
Reference in New Issue
Block a user