如何为每个调用服务?

How to call service with in for each?

private Payload(): asset { 
    const payload = { //pay load }
    return payload; 
}
  
public listofnumbers() { 
    number = [1,2,3]; 
    number.forEach(element => { 
        this.service(element); 
    }); 
}
 
private service(number) {
    this.service.getNumbers(this.Payload())
        .subscribe((res) => { 
            if (res.isSuccess && res.data) { 
                this.function(); 
            } 
        }) 
} 

function () { alert("fghj"); }

当调用服务而不是先执行 HTTP 调用时,它会调用内部服务中的方法。 不确定该怎么做?

使用 forkjoin

 public sendSelectedToD365() {
    let assetDetails1 = [];
      let assetSearchValue =(this.searchAssetForm.controls['assetSearch'].value).split(',');
      let mycalls = assetSearchValue.map(x => this.trying(x))
      forkJoin(mycalls).subscribe(res => {
        console.log(res)

      })
    }

  private trying(x)
      {     this.assetService.getAssetDetails(this.AssetDetailsPayload(x)).subscribe((res) => {
            if (res.isSuccess && res.data) {
              return res.data;
            }
        })
    }

这有什么问题吗?我正在使用 forkjoin 它没有按预期工作

@Sanjana,forkjoin 的“关键”是“加入”observable,因此“尝试”应该 return 一个 observable

  public sendSelectedToD365() {
      let assetDetails1 = [];
      let assetSearchValue =(this.searchAssetForm.controls['assetSearch'].value).split(',');
      let mycalls = assetSearchValue.map(x => this.trying(x))
      forkJoin(mycalls).subscribe(res:any[] => {
        console.log(res)
        // in res[0] you has the response to the first call
        // in res[1] you has the response to the second one
        // ...
        res.forEach((x,index)=>{
          console.log("The response to",assetSearchValue[index],"is ",res[index])
        })

      })
    }

  private trying(x):Observable<any>
  {         
       //see that you use return the Observable
         return this.assetService.getAssetDetails(this.AssetDetailsPayload(x))
  }