How to use a method from app.component in another component


#1

Hi every one
Im new at ionic so I apologize if my question is basic :smile:
I was able to add the ability to change the language of app using ngx-translate; and also change the rendering direction of page (RTL) and it works fine
Now Im trying to develop a setting page for my app which user can change the language of app from…
but Im not sure what is the best way to call methods from my app component here in my setting page so i can change the entire app language from here.
I know that there are 2 ways to communicate between components: using services or to use parent-child component relation but im havin problem realizing which one is the way to solve my problem.
thanks for helping me in advance

this is my app.component.ts code :

Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private translate: TranslateService) {
    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
  });

  
  translate.setDefaultLang('en');
  
  this.translate.onLangChange.subscribe((event: LangChangeEvent) =>
  {
    if(event.lang == 'ar')
    {
      platform.setDir('rtl', true);
      platform.setDir('ltr', false);
    }
    else
    {
      platform.setDir('ltr', true);
      platform.setDir('rtl', false);
    }
  });
}

  
  translateTo(language: string) {
    this.translate.use(language)

  }