Angular - Uncaught Error: Can't resolve all parameters for HomeComponent: (?, ?, ?, ?)

1285 views angular
-2

While running the angular project it comes with the error

Uncaught Error: Can't resolve all parameters for HomeComponent: (?, ?, ?, ?).

HomeComponent have four services called. All services are made Injectable. When all the services are removed from constructor runs fine but adding these services causes problems.

HomeComponent.ts

import { Component, OnInit } from '@angular/core';
import { PashminaModel } from '../../model/pashmina.model';
import { HomeService } from '../../services/home-service/home-service';
import { Category } from "../../enum/Enum";
import { FooterService } from "../../services/footer/footer.service";
import { NavbarService } from "../../services/navbar/navbar.service";
import { DataService } from '../../services/data-service/data.service';

@Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.scss']
})
constructor(
        private homeService: HomeService,
        private navService: NavbarService,
        private footerService: FooterService,
        private data: DataService
    ) {
}

------
-------

This is how I have implemented a provider section in app.module.ts

providers: [
        AuthorizationComponent,
        NavbarService,
        FooterService,
        LoginServiceEndpoint,
        LoginService,
        PashminaServiceEndpoint,
        PashminaService,
        ImageServiceEndpoint,
        ImageService,
        DescriptionServiceEndpoint,
        DescriptionService,
        ColorServiceEndpoint,
        ColorService,
        HomeService,
        HomeServiceEndpoint,
        AccountService,
        AccountServiceEndpoint,
        OrderServiceEndpoint,
        OrderService,
        DataService
    ],

Before it was working fine but suddenly appears this error.

answered question

Are all those object you injected in the ctor , in the providers section in app.module ?

@Eris- It seems fine in provider section. Can you tell me what might cause this

Can you paste the providers section ?

@Eris - I have pasted a provider section please have a look

are you using services in your services ? could it be you're missing @Injectable() decorator on one of your services ?

1 Answer

8

You have added AuthorizationComponent inside the providers, remove all the components from providers and add them under declarations

providers: [
        AuthorizationComponent,  //remove from here and add under declarations
        NavbarService,
        FooterService,
        LoginServiceEndpoint,
        LoginService,
        PashminaServiceEndpoint,
        PashminaService,
        ImageServiceEndpoint,
        ImageService,
        DescriptionServiceEndpoint,
        DescriptionService,
        ColorServiceEndpoint,
        ColorService,
        HomeService,
        HomeServiceEndpoint,
        AccountService,
        AccountServiceEndpoint,
        OrderServiceEndpoint,
        OrderService,
        DataService
 ]

posted this

Have an answer?

JD

Please login first before posting an answer.