Sequential code execution in angular/ typescript

后端 未结 7 2156
醉梦人生
醉梦人生 2021-01-01 06:02

How can I make my code run sequentially? For example,

  1. If I have a for loop which gets some data from a service, I want the n+1 iteration to run

相关标签:
7条回答
  • 2021-01-01 06:25
    SomeMethod(i, length){
           If(i< length){
              this.dataService.get(i).subscribe(  data => {
                     // do some business logic 
                     this.SomeMethod(i+1, length);
    
                }); 
           }else{
               console.log("Iteration completed");
           }}
    

    Try this logical way

    0 讨论(0)
提交回复
热议问题