javascript - 对于 Angular 8 - 无法通过 NgModuleFactoryLoader.load(path: string) 加载类型函数的Children
问题描述
我已从 Angular 7 升级到 Angular 8,并且我已将 loadChildren 的类型从 String 更改为 Function:
export interface DynamicComponentManifest {
componentId: string;
path: string;
loadChildren: Function;
}
现在,当我尝试通过 NgModuleFactoryLoader 加载方法加载 loadChildren 时,如下所示:
public getComponentFactory<T>(
componentId: string,
injector?: Injector,
): Observable<ComponentFactory<T>> {
const manifest = this.manifests.find(m => m.componentId === componentId);
if (!manifest) {
return throwError(`DynamicComponentLoader: Unknown componentId "${componentId}"`);
}
const p = this.loader.load(manifest.loadChildren).then(ngModuleFactory => {
const moduleRef = ngModuleFactory.create(injector || this.injector);
const dynamicComponentType = moduleRef.injector.get(DYNAMIC_COMPONENT);
if (!dynamicComponentType) {
throw new Error(
oneLine`DynamicComponentLoader: Dynamic module for componentId "${componentId}"
does not contain DYNAMIC_COMPONENT as a provider.`,
);
}
return moduleRef.componentFactoryResolver.resolveComponentFactory<T>(dynamicComponentType);
});
我在这一行遇到错误:
const p = this.loader.load(manifest.loadChildren).then(ngModuleFactory => {
错误:“函数”类型的参数不可分配给“字符串”类型的参数
我应该如何重新排列代码或修复代码?
解决方案
推荐阅读
- python - 基于另一个图形创建一个图形
- apache-camel - Apache camel - 如何检索给定组件的端点 URI
- python - Numpy 基于行索引沿轴应用
- flutter - future 方法在 null - flutter 中被调用
- c++ - 使用 reinterpret_cast 通过引用传递值
- terraform - 运行 EMR 作业流程时出错:ValidationException
- web-scraping - Python 从网络标头请求 403 Forbidden referer
- docker - 如何在 Host 模式下使用服务名访问容器?
- android - 如何在 Jetpack Compose 中使用图标切换按钮?
- image - 对 kubernetes 映像进行 prisma 扫描,其中 pip 易受攻击