0

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');
 }
Archimede
  • 699
  • 3
  • 15
  • 28
  • I assume you have tried with a console.log in translator too? If so, and it doesn't hit it , use the chrome developer tools to put a breakpoint and see what happens. – Jens Stragier Jan 16 '20 at 13:10
  • First, thank you very much. You right, I tried it and the console.log into translator function works fine but not the translator instruction itself. And, in Chrome dev tool, no error or warning. Thank you, is very important. – Archimede Jan 16 '20 at 13:24
  • What is the expected output? Do you have the german language file loaded? – Jens Stragier Jan 16 '20 at 13:26
  • Yes but as already told the translator itself is NOT a problem beacuse in the entire app it works fine. I.E., if I call this function from the lazy loaded component it self, at the opening the language change and the text appears. The problem is only if I try to change it from the main selector component. – Archimede Jan 16 '20 at 13:31

1 Answers1

1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Archimede
  • 699
  • 3
  • 15
  • 28