0
我正在用angular-cli
構建一個項目,在升級到1.0.0-rc.2
版本之後,我目前正在向ng build
發佈該應用的問題。當我嘗試這樣做,我收到以下錯誤:使用angular-cli @建設時提供商的問題最新
ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 46:16 in the original .ts file), resolving symbol AppModule in /Users/Rkok/Documents/Projects/capitola-vr-frontend/src/app/app.module.ts
錯誤位於app.module.ts
和它連接到useFactory
屬性提供商APP_INITIALIZER
內。這是完整的代碼:
@NgModule({
imports: [
// Modules list
],
declarations: [
// Declarations list
],
providers: [
{ provide: 'Window', useValue: Window },
PostsService,
UserService,
{
provide: APP_INITIALIZER,
useFactory: (users: UserService) =>() => users.onResize(), // The error is in this line
deps: [UserService],
multi: true
},
{
provide: APP_INITIALIZER,
useFactory: (posts: PostsService) =>() => posts.loadData(), // And in this other one
deps: [PostsService],
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule {}
您知道什麼是解決此問題的最佳方法嗎?提前感謝您的回覆!
謝謝你,但錯誤仍然存在。顯然我必須將函數存儲在服務或變量中,以這種方式傳遞值 –
您可以嘗試在同一個文件中用@NgModule裝飾器中的函數名稱聲明您的useFactory函數,並使用函數名稱在useFactory中引用它們 –
我有trie使用全局變量或導出常量,但它再次拋出錯誤。你會如何申報? –