I am currently developing an app where I need to make a GET request to retrieve data from a component. The issue I am facing is that the next step in the process is being executed before I receive a response from the service.
Below is my service file:
getSabhaListDetailsName(sabhaMandalName: string): Observable<any> {
const sabhaListDetailsNameURL = this.rooturl + 'sabhatypebysabhaname';
return this.http
.post(sabhaListDetailsNameURL,{}, { params: { sabha_name: sabhaMandalName } })
.pipe(map(this.extractData),
catchError(this.handleError<any>('sabhaListDetailsNameURL')));
}
This is the component file where I call the above service:
this.sabhaService.getSabhaListDetailsName(element.sabha_id).subscribe(result => {
this.tempRetrieveSabha = result.data.sabhaList;
//return this.tempRetrieveSabha;
// });
console.log(this.tempRetrieveSabha);
this.tempRetrieveSabha.forEach(
element1 => {
console.log(this.tempRetrieveSabha);
if (element1.sabha_type == element.sabha_type) {
this.tempSabha_ID = element1.id;
this.tempSabha_Type = element1.sabha_type;
this.tempFollowup_ID = element.followup_id;
}
})
});
My question is, how can I ensure that the HTTP request finishes before looping through the array?