Angular ngx-translate problem with forChild in non-lazy-load modules

Discussão em 'Angular' iniciado por ChopaKo, Dezembro 27, 2024.

  1. ChopaKo

    ChopaKo Guest

    I have problem with TranslateModule.forChild() in some case it doesn't triggered


    export function MainHttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, `${Environment.ASSETS_BASE_URL}/assets/i18n/main/`, '.json');
    }

    @NgModule({
    declarations: [
    AppComponent,
    ],
    exports: [],
    bootstrap: [AppComponent],
    imports: [
    CommonModule,
    TranslateModule.forRoot({
    loader: {
    provide: TranslateLoader,
    useFactory: MainHttpLoaderFactory,
    deps: [HttpClient]
    }
    }),
    ChildModule
    ]


    and ChildModule:



    export function ChildHttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, `${Environment.ASSETS_BASE_URL}/assets/i18n/child/`, '.json');
    }



    @NgModule({
    declarations: [ChildComponent],
    imports: [
    CommonModule,
    TableModule,
    TranslateModule.forChild({
    loader: {
    provide: TranslateLoader,
    useFactory: ChildHttpLoaderFactory,
    deps: [HttpClient]
    },
    extend: true
    }),
    ],
    providers: [TranslateService],
    exports: [
    ChildComponent
    ]
    })
    export class ChildModule {
    constructor(private translate: TranslateService) {
    this.translate.currentLang = '';
    this.translate.use('en');
    }
    }


    And this is problem, when I just import ChildModule to ParentModule and use component by tag, ChildHttpLoaderFactory doesn't triggered. But if you use lazy-load - everything is okay. So, maybe someone know how to trigger it?

    Thank you for your time

    Continue reading...

Compartilhe esta Página