In angular i want to create a multiple subscribe sequence. When the first subscribe is complete do next subscribe. Similar to this.
this.globalCtrl.getSon().subscribe(
response => {
this.son= response;
},
error => {
console.log(error);
},
() => {
//DOESN´T ENTER IN THIS SUBSCRIBE
this.dashboardCtrl.getMarkers(this.son).subscribe(
response => {
this.markers = response["body"]["data"];
if (this.markers.length == 0) {
this.toast.fire({
type: "error",
title: "No hay datos geográficos del grupo seleccionado"
});
}
this.timezone = response["body"]["timezone"];
},
error => {
console.log(error);
}
);
The problem: Doesn't enter in the second subscription and the 'response' has data. ¿Anyone know how can i do that?
UPDATE
If i put second subscription inside response like this
this.globalCtrl.getSon().subscribe(
response => {
this.son= response;
this.dashboardCtrl.getMarkers(this.son).subscribe(
response => {
this.markers = response["body"]["data"];
if (this.markers.length == 0) {
this.toast.fire({
type: "error",
title: "No hay datos geográficos del grupo seleccionado"
});
}
this.timezone = response["body"]["timezone"];
},
error => {
console.log(error);
}
);
Works but view doesn´t show data. When i refresh the view data load properly, but in first load doesn´t load data.
UPDATE 2: USING SWITCH MAP
this.globalCtrl.getfather().pipe(
switchMap(son=> this.dashboardCtrl.getMarkers(son.toString()).subscribe( /ERROR
response => {
this.markers = response["body"]["data"];
if (this.markers.length == 0) {
this.toast.fire({
type: "error",
title: "No hay datos geográficos del grupo seleccionado"
});
}
this.timezone = response["body"]["timezone"];
},
error => {
console.log(error);
}
)
);
The propierty subscribe doesn´t exist in OperatorFunction
Maybe the observable cause the error
getFather(): Observable<any> {
return this.grupo.asObservable();
}