1

After installing Angular-cli I am getting this error:

Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a refer
ence to an exported function (position 55:19 in the original .ts file), resolving symbol AppModule in C:/TM-2013/Debt/Debt Platform/Code/main/Think.Debt.Presentation/deb-explorer-with-angular
-cli/src/app/app.module.ts    

In my App.Module.ts it does not like this section of code:

providers: [

//   These are needed throughout the site    
AppConfigService,

{ provide: APP_INITIALIZER, useFactory: configServiceFactory, deps: [AppConfigService], multi: true },
{
  provide: HttpService,
  useFactory: (backend: XHRBackend, options: RequestOptions) => {
    return new HttpService(backend, options);
  },
  deps: [XHRBackend, RequestOptions]
}

],

EDIT:

with the .load

  { provide: APP_INITIALIZER, useFactory: (config: AppConfigService) => () => config.load(), deps: [AppConfigService], multi: true },
    {
      provide: HttpService,
      useFactory: (backend: XHRBackend, options: RequestOptions) => {
        return new HttpService(backend, options);
      },
      deps: [XHRBackend, RequestOptions]
    }

Is it possible to turn this into a factory class as it does not like this current usage?

1 Answer 1

3

Do exactly as it suggested:

// named exported function
export function httpFactory(backend: XHRBackend, options: RequestOptions) {
    return new HttpService(backend, options);
}

export function configServiceFactory(config: AppConfigService) {
    return () => config.load();
}

// after goes declaration of you module with `providers`
// ... skipped ...
{ provide: APP_INITIALIZER, useFactory: configServiceFactory, deps: [AppConfigService], multi: true },
{
    provide: HttpService,
    useFactory: httpFactory,  // reference to the function
    deps: [XHRBackend, RequestOptions]
}
// ... skipped ...
Sign up to request clarification or add additional context in comments.

4 Comments

What do you mean?
@Funky you can use same approach with exported named function for it as well.
Not quite sure how?
Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! You are awesome!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.