feat(core): expose inputs
, outputs
and ngContentSelectors
on ComponentFactory
. (#15214)
E.g. for a component like this: ``` @Component({ template: ‘<ng-content select=“child”></ng-content>’ }) class MyComp { @Input(‘aInputName’) aInputProp: string; @Output(‘aEventName’) aOuputProp: EventEmitter<any>; } ``` the `ComponentFactory` will now contain the following: - `inputs = {aInputProp: ‘aInputName’}` - `outputs = {aOutputProp: ‘aOutputName’}` - `ngContentSelectors = [‘child’]`
This commit is contained in:

committed by
Miško Hevery

parent
604546c287
commit
791534f2f4
@ -142,7 +142,26 @@ export class CompileMetadataResolver {
|
||||
ngfactoryFilePath(dirType.filePath), cpl.componentFactoryName(dirType));
|
||||
} else {
|
||||
const hostView = this.getHostComponentViewClass(dirType);
|
||||
return createComponentFactory(selector, dirType, <any>hostView);
|
||||
// Note: inputs / outputs / ngContentSelectors will be filled later once the template is
|
||||
// loaded.
|
||||
return createComponentFactory(selector, dirType, <any>hostView, {}, {}, []);
|
||||
}
|
||||
}
|
||||
|
||||
private initComponentFactory(
|
||||
factory: StaticSymbol|ComponentFactory<any>, inputs: {[key: string]: string},
|
||||
outputs: {[key: string]: string}, ngContentSelectors: string[]) {
|
||||
if (!(factory instanceof StaticSymbol)) {
|
||||
for (let propName in inputs) {
|
||||
const templateName = inputs[propName];
|
||||
factory.inputs.push({propName, templateName});
|
||||
}
|
||||
const outputsArr: {propName: string, templateName: string}[] = [];
|
||||
for (let propName in outputs) {
|
||||
const templateName = outputs[propName];
|
||||
factory.outputs.push({propName, templateName});
|
||||
}
|
||||
factory.ngContentSelectors.push(...ngContentSelectors);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,6 +205,11 @@ export class CompileMetadataResolver {
|
||||
componentFactory: metadata.componentFactory,
|
||||
template: templateMetadata
|
||||
});
|
||||
if (templateMetadata) {
|
||||
this.initComponentFactory(
|
||||
metadata.componentFactory, metadata.inputs, metadata.outputs,
|
||||
templateMetadata.ngContentSelectors);
|
||||
}
|
||||
this._directiveCache.set(directiveType, normalizedDirMeta);
|
||||
this._summaryCache.set(directiveType, normalizedDirMeta.toSummary());
|
||||
return normalizedDirMeta;
|
||||
|
Reference in New Issue
Block a user