Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use service in Angular ngModule

Here is a shared module and I want to use translate service inside module but the problem here is that setCulture(translate.currentLang); the translate here is unknown.

import { CommonModule } from '@angular/common';
import { inject, NgModule } from '@angular/core';
import * as ejsTranslation from './ejs-translations.json';
import { L10n, setCulture } from '@syncfusion/ej2-base';
import { TranslateService } from '@ngx-translate/core';


setCulture(translate.currentLang);
L10n.load(ejsTranslation);

@NgModule({
  declarations: [
  ],
  imports: [
    CommonModule
  ],
  providers: [TranslateService]
})
export class SharedModule { }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can try initializing on the module level, like so.

import { CommonModule } from '@angular/common';
import { inject, NgModule } from '@angular/core';
import * as ejsTranslation from './ejs-translations.json';
import { L10n, setCulture } from '@syncfusion/ej2-base';
import { TranslateService } from '@ngx-translate/core';
...
@NgModule({
  declarations: [
  ],
  imports: [
    CommonModule
  ],
  providers: [TranslateService]
})
export class SharedModule { 
 constructor(private translate: TranslateService) {
   setCulture(translate.currentLang);
 }
}

SyncFusion Code Reference

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading