Angular(7)材料表在更改时更新

时间:2019-04-25 09:08:26

标签: angular

为什么在订阅过程中,母体表不根据更改的响应进行更新?

响应将包含以下元素: a ,b,c,d和e元素。

但是,由于实现中另一个要求获得完整结果的请求,log()中的响应顺序为b,c,d,e和 a

来电者:

this._pearlmillService.getAllPearlMillsAndAssociatedPulpVessels().subscribe((response: PearlMill[]) => {
      console.log(response);

      this.dataSource.data = response;
      setTimeout(() => this.dataSource.sort = this.sort);    
    }
});

实施:

getAllPearlMillsAndAssociatedPulpVessels(): Observable<PearlMill[]> {
    this._http.get<PearlMill[]>(`${this.baseUrl}/GetAll`).subscribe((pearlMillResponse: PearlMill[]) => {
      for (let i = 0; i < pearlMillResponse.length; i++) {
        // no more data to GET - just return what we have
        if (pearlMillResponse[i].pulpVessel === null) {
          this.pearlMillsAndAssociatedPulpVessels.push(pearlMillResponse[i]);
          continue;
        }

        // there is more data to GET - fetch it
        this._pulpVesselService.getById(pearlMillResponse[i].pulpVessel.id).subscribe((pulpVesselResponse: IPulpVessel) => {
          pearlMillResponse[i].pulpVessel = pulpVesselResponse;
          this.pearlMillsAndAssociatedPulpVessels.push(pearlMillResponse[i]);          
        });        
      }
    });
    return of(this.pearlMillsAndAssociatedPulpVessels);
  }

响应顺序:

https://i.imgur.com/6ZTWKmP.png

HTML表将仅显示b-e,而不显示a,因为第二秒后它会出现“ a” 的一小部分。

0 个答案:

没有答案