tal*_*d24 5 typescript angular
我一直在尝试将我的应用程序切换到AoT编译,并在应用程序加载时在生产环境中收到此错误(它在本地工作正常).
Error: Can't resolve all parameters for IconService: (?, ?)
似乎错误来自提供IconService的模块.图标服务构造函数看起来像
constructor(private http:Http, private iconConfiguror:IconConfiguror) {
所以我的问题是这个错误是什么意思,为什么它只会在prod环境中发生(我尝试在本地启用prod模式)?
现在看来似乎意味着,不设置http和图标的配置参数,但在应用程序模块水平设置的图标配置和HttpModule在所述进口IconModule,其中IconService被提供.
@NgModule({
imports: [
CommonModule,
HttpModule,
],
declarations: [
IconComponent,
],
exports: [
IconComponent,
],
providers: [
IconService,
__platform_browser_private__.BROWSER_SANITIZATION_PROVIDERS,
],
})
Run Code Online (Sandbox Code Playgroud)
和我们的图标组件的桶.
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";
Run Code Online (Sandbox Code Playgroud)
通过以不同方式提供IconService来解决此问题.
{
provide: IconService,
useFactory: iconServiceFactory,
deps: [Http, IconConfiguror],
},
Run Code Online (Sandbox Code Playgroud)
和工厂本身
export function iconServiceFactory(http: Http, iconConfiguror: IconConfiguror) {
return new IconService(http, iconConfiguror);
}
Run Code Online (Sandbox Code Playgroud)
我想由于某些原因没有提供Http(即使导入了HttpModule),所以我不得不将它声明为依赖项.
| 归档时间: |
|
| 查看次数: |
16517 次 |
| 最近记录: |