Home > Mobile >  Angular Translate arrow function factory
Angular Translate arrow function factory

Time:04-13

When I import TranslateModule using this code:

TranslateModule.forRoot({
    loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
    }
})

where

export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
}

everything works but if I use an arrow function:

export const HttpLoaderFactory = (http: HttpClient) => new TranslateHttpLoader(http, "./assets/i18n/", ".json");

I got this error:

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)

Why is this happening?

Thanks

CodePudding user response:

i think this simply isn't supported in angular AOT.

Here is a list of supported features and the issue mentioning it

  • Related