Angular 当OnInit中的lang更改时,translateService.onLangChange.subscribe不会触发

Angular 当OnInit中的lang更改时,translateService.onLangChange.subscribe不会触发,angular,service,subscribe,ngx-translate,date-pipe,Angular,Service,Subscribe,Ngx Translate,Date Pipe,所以我在一个组件中使用了translateService.onLangChange.subscribe,它工作得很好,但它创建了一个单独的服务,它将订阅langChange并为我设置一个localeDate。但是,当我更改语言时,它不会注册它,也不会执行任何操作 ngOnInit(): void { this.getLocaleDateFormat(); this.translateService.onLangChange.subscribe(() => this.getL

所以我在一个组件中使用了translateService.onLangChange.subscribe,它工作得很好,但它创建了一个单独的服务,它将订阅langChange并为我设置一个localeDate。但是,当我更改语言时,它不会注册它,也不会执行任何操作

ngOnInit(): void {
    this.getLocaleDateFormat();
    this.translateService.onLangChange.subscribe(() => this.getLocaleDateFormat());
  }
getLocaleDateFormat() {
    // To add another lang it has to be added to Languages bellow to match the locale_id of the lang and in main module it has to be imported and registered
    this.dateAdapter.setLocale(Languages[this.translateService.currentLang]);
    this.currLang = Languages[this.translateService.currentLang];
    console.log('locale-date-adapters currLang: ' + this.currLang);
    return this.currLang;
  }
此外,每次更改lang时,我希望我的组件从getLocaleDataFormat()获取该值,而不必

this.translateService.onLangChange.subscribe(() => thisLocaleDateAdapterService.getLocaleDateFormat()); 
在我的组件中。我尝试订阅它,但出现了一个错误,它不是一个函数

这就是我所尝试的:

this.localeDateAdapterService.getLocaleDateFormat().subscribe(currLang => this.currLang = currLang);
我基本上希望它监听getLocaleDataFormat,并在其更改时更改值

更新:
我刚刚意识到问题出在没有触发语言变化的OnInit上。LangChange在函数中的服务中触发,但在OnInit中不触发。忘记将调用onLang的服务放入主模块提供程序中