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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -