[SOLVED]Cannot resolve all parameters for 'CustomComponent'. Make sure that all the parameters are decorated with Inject

Hi all!

I’m trying to build an ionic app that’s pretty loosely based on an angular 2 app that I’ve got up and running. In the process, I’m reorganizing a little and running into some problems that I didn’t have on my web app. For example, I get the following error:

Cannot resolve all parameters for 'DashboardWorkoutComponent'(undefined, HttpClient). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'DashboardWorkoutComponent' is decorated with Injectable.

Here’s the code I’ve got (into gists so it’s easier to see):

I didn’t have this problem on the angular app, but the user-dashboard page was a component there, so am I not just understanding how to inject components into pages?


You need provide APIService into component or you need use something this:
providers: [CORE_DIRECTIVES, HttpClient, APIService], directives: [DashboardWorkoutComponent)]

Your singleton APIService isn’t created.

I have the same error here, i provide my service to providers and into my component but the same error shown

Need help

No code - no solution )

I added this into app/components/dashboard-workout.component.ts like you mentioned @xr0master and I still get the same error:

  providers: [CORE_DIRECTIVES, HttpClient, APIService],
  directives: [DashboardWorkoutComponent]

Man, I am strongly recommend you read Angular 2 docs.

My code fix your user-dashboard.ts. I don’t said you put it to component :wink:

@xr0master My apologies, I misunderstood which file you meant. Can you point me in the direction of this specific documentation? Would that be dependency injection?

I also did the above in app/pages/user-dashboard/user-dashboard.ts and it gave me the same error.

Um… it is strange… So, a service is singleton but something must create service instance. At time, when you call your component, the service still isn’t created. You need use provide (once), that it creates the instance of service. Your project has dependency loop, and it is your issue.

Sorry for my bad English )

I recommend
and after this read dependency injection.

PS ionic does bootstrap, so if you want create service for all app, you can put the service to app provider.

Thanks a lot @xr0master. I ended up refactoring it a little and stopped the services from depending on each other and the error went away! So let that be a lesson to me, don’t chain dependencies in your services!