This is my first question in stackoverflow, even though I've been a user for many years. I'm relatively new to Angular and could see several answers to similar questions in this space, but I still coudn't get it working.
Sorry, if I'm duplicating the request. I'm subscribing some data and wish to assign and use it in local variable and process further.
ngOnInit() {
this.someMethod().subscribe(data => this.shuttleArea = data);
console.log('OUTER: '+JSON.stringify(this.shuttleArea));}
Following function fetches the data from a service.
someMethod(){
return this.catalogueService['getShuttleRoute']().pipe(map(data => {
this.shuttleArea = JSON.parse('{"options":'+ JSON.stringify(data[0].value) +'}');
console.log('INNER: '+ JSON.stringify(this.shuttleArea));
return this.shuttleArea;
})); }
I'm getting expected service response in console with INNER text. But when I consume it on oninit, console OUTER displays "undefined". My objective is not to display in console, but need to do additional calculations under oninit or someother sub function.
INNER, OUTER & console has been used to simplify the problem, and make the objective clear. Any help would be greatly appreciated.