I get data of several APIs, put the data in arrays and filter these arrays. To ensure they are all executed correctly, I nested all the get-Calls inside each other - but the more get-Calls there are the messier it will get
this.http.get(url1).subscribe
(data1 => {
// code code code //
this.http.get(url2).subscribe
( data2 =>
{ /* code code code */ }/* end of 2nd request subscribe function*/
}// end of 1st request subscribe function
So I created a service.ts, with al the get-Calls
//code
getData1(){/*code*/}
getData2(){/*code*/}
getData3(){/*code*/}
}
and in the detail.component.ts I filled the arrays:
//code
ngOnInit()
{
this.Service.getData1()
.subscribe(/*fill array1 with data*/)
this.Service.getData2()
.subscribe(/*fill array2 with data*/)
{
Even though the first subscription works fine, the second doesn't - but I can't figure out why. I basically try to find all the items that have the defined id:
//code
public data2: any = []
public id = '123'
//code
ngOnInit()
{
//code
this.Service.getData2()
.subscribe
(data2 =>
{
this.data2 = data2.filter(item => item.id === this.id)
return data2
}
)
//code
}
Is there any mistake in the filtering maybe?