As you do, you don't wait for the subscribe to complete to apply the filter.
Using forkJoin
, as you say, is a good option to wait for the two subscribe to be done.
You can do it like this
const result =[]
forkJoin([
this.fncservice.obs,
this.analysefncservice.obs
]).subscribe((result) => {
this.fncservice.maptofncbyetat(result[0],this.fnc,"en cours")
this.analysefncservice.maptoplanactionbyetat(result[1],this.analysefncs,"en cours")
this.fnc.forEach((filter) => {
if (
!this.analysefncs
.filter((condition) => condition.n_fnc == filter.n_fnc)
.some((nc) => nc.etat != "act")
) {
console.log("succes" , filter.n_fnc)
result.push(filter.n_fnc);
}
});
},(error) => {
// error message
})
Because of
forkJoin : Accepts an Array of ObservableInput or a dictionary Object of ObservableInput and returns an Observable that emits either an array of values in the exact same order as the passed array, or a dictionary of values in the same shape as the passed dictionary.
I first suppose that this.fncservice.obs
and this.analysefncservice.obs
are both Observable
.
And then, as you can see, in the subscribe of the forkJoin
, I send result[0]
and result[1]
as you did in each subscribe before.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…