Search code examples
angularjsangular-i18n

Angular: translate function not reachable from other component


in my Angular App I have a main component A and a sub component B loaded by lazy loading.

In this sub component B I have the following functions:

  translator(){

    this.translate.use('de');
  }

  checkText(){

    console.log('check text works!')
  }

And, if I call this 2 functions from A by:

  this.administrationMainComponent.checkText();

  this.administrationMainComponent.translator();

Only the check text works.

1) Sure is not a problem of translator in B itself (if I execute it from the constructor of B, it works perfectly);

2) Sure, is not a problem about Injectable or something similar, because the check text works perfectly if I call it from A

How can I solve the problem and execute correctly translator from A?

EDIT: Also by this way it doesn't work

 translator = () => {

    console.log('check translator text!');
    this.translate.use('de');
 }

Solution

  • https://medium.com/@lopesgon/translate-angular-4-with-ngx-translate-and-multiple-modules-7d9f0252f139

    This is the solution: put the translator part of the module in an external shared module and shared the same from it.