Angular 2 call function with subscribe inside a for loop -


i have function subscription service inside:

selectcar(carnumber) {   this.carservice.getcarbynumerator(carnumber)     .subscribe( (car) => {                   console.log(carnumber);                   //more stuff here                 },                 (err) => console.log(err)                ); } 

i want call function inside loop following:

for(let carnumber of carnumbers) {     this.selectcar(carnumber); } 

the issue is, sometime works expect, order not in list.

e.g. list is:

45 67 89 

but when in console, see following:

67 89 45 

how can force loop not go next item till current function call finished?

i guess flatmap in case.

observable.of(carnumbers) .flatmap(term => this.selectcar(term)) .subscribe( (car) => {         console.log(carnumber);         //more stuff here     },     (err) => console.log(err) ); 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -