Reputation: 31
I have upgraded from Angular 7 to Angular 8 and I have changed the type of loadChildren from String to Function:
export interface DynamicComponentManifest {
componentId: string;
path: string;
loadChildren: Function;
}
And now when I am trying to load the loadChildren via NgModuleFactoryLoader load method like this:
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);
});
I am getting an error at this line:
const p = this.loader.load(manifest.loadChildren).then(ngModuleFactory => {
The error: Argument of type 'Function' is not assignable to parameter of type 'string'
How should I rearrange the code or fix the code?
Upvotes: 1
Views: 101