Uncaught Error: Can't resolve all parameters for MyService: ([object Object], ?). #146

Closed
opened 2025-08-09 17:15:10 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @Basel78 on 3/5/2018

Hello,
I have built service library using "generator-angular2-library" template and updated it with angular V "^4.4.6", then used it in andular-cli all working fine..
The library module looks like

export class ServiceLibraryModule { 
  static forRoot(config:any): ModuleWithProviders {
    return {
      ngModule: ServiceLibraryModule ,
      providers: [Serv1
        Serv2 
        { provide: MODULE_CONFIG, useValue: config }]
    };
  }
}

where export const MODULE_CONFIG = new InjectionToken<any>('');
to pass config parameters to the services of the library before using it.

now when I want to reuse my library in aspnetcore angular SPA project with V "^4.4.6", I added the "ServiceLibraryModule " to "app.shaed.module.ts" of the Angular-SPA project similar to what I did in angular-cli,

 imports: [...
ServiceLibraryModule .forRoot({"config_url" : "http://somedomain"}),
....]

but I keep getting the error:
"Uncaught Error: Can't resolve all parameters for Serv2 : ([object Object], ?)."

the Ser2 class looks like

export class Serv2
{

    constructor( private http: Http,@Inject(MODULE_CONFIG) private config:any){}
.....
}

can you help me find out what I did wrong or how to fix this issue in Angular-SPA, as the services library is working fine in angular-cli same version "^4.4.6".

*Originally created by @Basel78 on 3/5/2018* Hello, I have built service library using "generator-angular2-library" template and updated it with angular V "^4.4.6", then used it in andular-cli all working fine.. The library module looks like ``` export class ServiceLibraryModule { static forRoot(config:any): ModuleWithProviders { return { ngModule: ServiceLibraryModule , providers: [Serv1 Serv2 { provide: MODULE_CONFIG, useValue: config }] }; } } ``` where `export const MODULE_CONFIG = new InjectionToken<any>('');` to pass config parameters to the services of the library before using it. now when I want to reuse my library in aspnetcore angular SPA project with V "^4.4.6", I added the "ServiceLibraryModule " to "app.shaed.module.ts" of the Angular-SPA project similar to what I did in angular-cli, ``` imports: [... ServiceLibraryModule .forRoot({"config_url" : "http://somedomain"}), ....] ``` but I keep getting the error: "Uncaught Error: Can't resolve all parameters for Serv2 : ([object Object], ?)." the Ser2 class looks like ``` export class Serv2 { constructor( private http: Http,@Inject(MODULE_CONFIG) private config:any){} ..... } ``` can you help me find out what I did wrong or how to fix this issue in Angular-SPA, as the services library is working fine in angular-cli same version "^4.4.6".
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#146
No description provided.