0
public GetTranslation = (SourceEnglish: string, LanguageId: number, CompanyId: number): string => {
  this.api.GetTranslate(SourceEnglish, LanguageId, CompanyId).subscribe(
    (res: any) => {
      this.SourceResult = res[0].SourceResult;
      // Work Done
      console.log(this.SourceResult);
    },
    err => {
      console.log(err);
    }
  );
  // undefined
  console.log(this.SourceResult);
  return this.SourceResult;
}
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
  • If you need to return data then Possible duplicate of [angular 2 how to return data from subscribe](https://stackoverflow.com/questions/39295854/angular-2-how-to-return-data-from-subscribe) – Prashant Pimpale Nov 14 '19 at 05:46

1 Answers1

0

Use the async pipe

translatedText$ = this.api.GetTranslate(SourceEnglish, LanguageId, CompanyId).pipe(
  map(res => res[0].SourceResult)
);

and in the template

{{ translatedText$ | async }}

No need for any subscriptions as the async pipe manages the subscribing for you.

Adrian Brand
  • 20,384
  • 4
  • 39
  • 60