I need to return a value from subscribe since I cannot set in a global variable. However, the function always returns before the value is assigned the data from the subscribe. I tried all the answers suggested in posts in the topic but it didn't work
getMessage(field): string {
this.service.getMessage(field).subscribe(mssg => {
let message = '';
message = mssg;
return message;
});
}
The calling function: (It's called several times in the component) it's inside setting values for angular material table
something like
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: data?
this.getMessage(obj) + ' ' + someobj.id
, weight: 1.0079, symbol: 'H'},
{position: 2, name: ess?
this.getMessage(se) + ' ' + yy.gt, weight: 4.0026, symbol: 'He'},
,
];