Error while injecting @ngx-translate/core using Injector.create

Viewed 22

I am injecting TranslateService from @ngx-translate/core in my fc.helper.ts like this.

const injector = Injector.create({
  providers: [{ provide: TranslateService, deps: [] }],
});
const translate: TranslateService = injector.get(TranslateService);

and am calling it in my fc.helper.ts like this.

const cloneCourse = translate.instant('calendar.cloneCourse');

And I get an error like

ERROR TypeError: Cannot read properties of undefined (reading 'translations')
at get translations [as translations] (ngx-translate-core.mjs:346:63)
at TranslateService.instant (ngx-translate-core.mjs:580:45)
...

What could be wrong with my injection?

Using,

  1. @angular/core: 13.3.3
  2. @ngx-translate/core: 14.0.0

P.S: @ngx-translate/core constructor injection constructor(private translate: TranslateService) works well used elsewhere(i.e., services and components)

0 Answers
Related