Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "Can't resolve all parameters for e: (?)."

I have such kind of error after deployment to github-pages with angular-cli:

Error: "Can't resolve all parameters for e: (?)."

Local application works. What steps would you recommend to do to find the problem place?

Tried with angular-cli beta29 and beta30.

UPD: I've removed Router from the application for testing purposes. Not I have only one guess that it's something with DI.

UPD2(FOUND THE PLACE):

The problem is with overwriting RequestOptions, so do:

export class RequestOptionsService extends RequestOptions {}

and for provider definition:

{ provide: RequestOptions, useClass: RequestOptionsService },

It's still a question for me.

  • do not overwrite RequestOptions constructor - error.
  • overwrite RequestOptions constructor with empty parameter - no error
  • overwrite RequestOptions constructor with parameters - error

This is the way how I overwrite the constructor:

constructor(options?: RequestOptionsArgs) {
  super(options);
}

What could be wrong here?

UPD3(Solved own case):

The problem indeed was with RequestOptions, so you should not do:

export class RequestOptionsService extends RequestOptions {}

but only:

export class RequestOptionsService extends BaseRequestOptions {}
like image 226
Stepan Suvorov Avatar asked Feb 03 '17 11:02

Stepan Suvorov


2 Answers

Make sure:

  • you have "emitDecoratorMetadata": true in your tsconfig.js
  • every service is not missing @Injectable() decorator
  • components constructor injects your services (have them passed as parameters)
like image 73
smartmouse Avatar answered Oct 20 '22 16:10

smartmouse


Official example is:

 class MyOptions extends BaseRequestOptions {
   search: string = 'coreTeam=true';
 }

 bootstrap(App, [HTTP_PROVIDERS, {provide: RequestOptions, useClass: MyOptions}]);

In fact, export class RequestOptionsService extends RequestOptions {} should also work perfectly fine. May be it is angular-cli specific problem (i can do this on my setup).

If your service has non-optional parameter then @Injectable() is a must. Also parameters must be provided (RequestOptionsArgs in your case) or marked as @Optional().

like image 1
kemsky Avatar answered Oct 20 '22 16:10

kemsky