Angular 6 Service
getProjectEpics(id: string): Observable<any> {
return this.http.get<any>(this.baseUrl + 'getEpics/' + id);
}
Component Angualr 6
projectEpics=[];
getProjectEpics(id: string) {
this.epicService.getProjectEpics(this.id).subscribe(
next => {
console.log('RESPONSE', next);
this.projectEpics = next[0].epics;
console.log(this.projectEpics); // array has data
},
error => {
this.alertify.error(error);
}
);
console.log(this.projectEpics); // The array is empty at this log.
}
I am using Angularr 6. I have a method returning observable of type any getProjectEpics in serive which is calling an API. Then in my component i am subscribing to observable method avaliable in service. I successfully get the data from the API and serive but issue is that when i assign the data present in next object to my local array projectEpics and log projectEpics array inside next to console, it displays the array but, when i log it outside next or outside subscribe the projectEpics array is empty and shows no data.