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

前端 未结 6 994
南旧
南旧 2021-01-19 00:32

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).

6条回答
  •  旧时难觅i
    2021-01-19 01:06

    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.

提交回复
热议问题