Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - Error: Can't resolve all parameters for IconService

I've been trying to switch my app over to AoT compilation and have been getting this error in the production environment when the app is loading (it works fine locally).

Error: Can't resolve all parameters for IconService: (?, ?)

it seems like the error is coming from on the modules that is providing the IconService. The icons services constructor looks like

constructor(private http:Http, private iconConfiguror:IconConfiguror) {

So my question is what does this error mean and why would it happen in the prod environment only (I've tried enabling prod mode locally)?

It seems like it means that the http and icon configuration parameters aren't provided, but the icon config is provided at the app module level and the HttpModule is imported in the IconModule where the IconService is provided.

@NgModule({
    imports: [
        CommonModule,
        HttpModule,
    ],
    declarations: [
        IconComponent,
    ],
    exports: [
        IconComponent,
    ],
    providers: [
        IconService,
        __platform_browser_private__.BROWSER_SANITIZATION_PROVIDERS,
    ],
})

And the barrel for our icon component.

export * from "./components/icon/icon.configuror";

export * from "./components/icon/icon.service.provider";

export * from "./components/icon/icon.service";

export * from "./components/icon/icon.component";

export * from "./components/icon/icon.module";
like image 817
tallkid24 Avatar asked Feb 23 '17 20:02

tallkid24


1 Answers

Fixed this by providing the IconService in a different way.

    {
        provide: IconService,
        useFactory: iconServiceFactory,
        deps: [Http, IconConfiguror],
    },

and the factory itself

export function iconServiceFactory(http: Http, iconConfiguror: IconConfiguror) {
    return new IconService(http, iconConfiguror);
}

I guess for some reason the Http wasn't being provided (even though HttpModule was imported) so I had to declare it as a dependency.

like image 143
tallkid24 Avatar answered Sep 21 '22 07:09

tallkid24