Angular 翻译箭头函数工厂
Angular Translate arrow function factory
当我使用此代码导入 TranslateModule
时:
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
哪里
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
}
一切正常,但如果我使用箭头函数:
export const HttpLoaderFactory = (http: HttpClient) => new TranslateHttpLoader(http, "./assets/i18n/", ".json");
我收到这个错误:
Uncaught ReferenceError: Cannot access 'HttpLoaderFactory' before initialization
at Module.HttpLoaderFactory (app.component.ts:18:26)
at Module.10617 (core-components.module.ts:18:29)
at __webpack_require__ (bootstrap:19:1)
at Module.36747 (app.component.ts:18:26)
at __webpack_require__ (bootstrap:19:1)
at Module.14431 (environment.ts:33:68)
at __webpack_require__ (bootstrap:19:1)
at __webpack_exec__ (.*$:292:1)
at .*$:292:1
at Function.__webpack_require__.O (chunk loaded:23:1)
为什么会这样?
谢谢
我认为 angular AOT 根本不支持它。
当我使用此代码导入 TranslateModule
时:
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
哪里
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
}
一切正常,但如果我使用箭头函数:
export const HttpLoaderFactory = (http: HttpClient) => new TranslateHttpLoader(http, "./assets/i18n/", ".json");
我收到这个错误:
Uncaught ReferenceError: Cannot access 'HttpLoaderFactory' before initialization
at Module.HttpLoaderFactory (app.component.ts:18:26)
at Module.10617 (core-components.module.ts:18:29)
at __webpack_require__ (bootstrap:19:1)
at Module.36747 (app.component.ts:18:26)
at __webpack_require__ (bootstrap:19:1)
at Module.14431 (environment.ts:33:68)
at __webpack_require__ (bootstrap:19:1)
at __webpack_exec__ (.*$:292:1)
at .*$:292:1
at Function.__webpack_require__.O (chunk loaded:23:1)
为什么会这样?
谢谢
我认为 angular AOT 根本不支持它。