• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

256
Views
For Angular 8 - cannot loadChildren of type function via NgModuleFactoryLoader.load(path: string)

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?

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error