Hello,

When I make a call to the function submit() I need to loop on multiple http 
post request and at the end I want to display 2 counters : nbOk and nbKo.
The problem is that due to asynchron process, the counters display the 
wrong value because all the requests are not complete.

I suppose that i should use observables but I'm not very comfortable with 
that.

in components.ts : 


...
submit(){

 for (const record of this.csvRecords){
   this.addDemande(record);
 }

 console.log(this.cptNbDemandeOk)     //  -> wrong value !!
 console.log(this.cptNbDemandeErr)     //  -> wrong value !!
}


addDemande(id){

 this.listeEnvironnementsCible.forEach( (env) => {
  if (env.selected){
     this.newDemande = new Demande;

     this.newDemande.dicid = this.dicid;
 
     this.datasService.postDemande(this.newDemande)
      .subscribe(
        () => {
          this.cptNbDemandeOk++;
        },
        error => {
           console.error('Une erreur client side est survenue : ')
           this.cptNbDemandeErr++;
        }
      );
  }
 })
}



in data.service.ts :


...
postDemande(demande : Demande) {
  return this.http.post('/je-extracteur-exlodia-rest/ajoutdemande/' + 
demande.dicid, httpOptions)
}
...


How should I use Observables to get the correct counter values ?

Thank you very much

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to