【发布时间】:2018-06-26 06:49:55
【问题描述】:
是否可以从字符串中解析组件?
以前在 Angular 2 中,我们可以做到这一点see here。但是,在 Angular 4 中,同样的方法会抛出错误。
private resolver: ComponentFactoryResolver
var factories = Array.from(this.resolver['_factories'].keys());
var factoryClass = <Type<any>>factories.find((x: any) => x.name === this.comp);
const factory = this.resolver.resolveComponentFactory(factoryClass);
const compRef = this.vcRef.createComponent(factory);
【问题讨论】:
-
错误是什么?
-
元素隐式具有 'any' 类型,因为 'ComponentFactoryResolver' 没有索引签名
标签: angular