Angular 被调用方法中的TypeScript数组修改未反映在调用函数中

Angular 被调用方法中的TypeScript数组修改未反映在调用函数中,angular,typescript,Angular,Typescript,我有以下调用组件代码: this.appDowntimeService.getAllApplications(this.message, this.appDetails); 以下是被调用的服务方法: async getAllApplications(message: any[], appDetails: any[]) { this.http.get(environment.serverTMODowntime + '/tmodowntime.v1/downtime/apps/all'

我有以下调用组件代码:

this.appDowntimeService.getAllApplications(this.message, this.appDetails);
以下是被调用的服务方法:

  async getAllApplications(message: any[], appDetails: any[]) {
    this.http.get(environment.serverTMODowntime + '/tmodowntime.v1/downtime/apps/all', {headers: this.headers})
      .subscribe((res: any[]) => {
        message.length = 0;
        appDetails.length = 0;
        res.forEach(x => {
          message.push(x);
          x.details.forEach(y => {
            const appDetail = <ApplicationDetail>{};
            appDetail.createdDate = y.createdDate;
            appDetail.createdBy = y.createdBy;
            appDetail.updatedDate = y.updatedDate;
            appDetail.updatedBy = y.updatedBy;
            appDetails.push(appDetail);
          });
        });
        appDetails.sort((leftSide, rightSide) => {
          if (leftSide.startTime < rightSide.startTime) return -1;
          if (leftSide.startTime > rightSide.startTime) return 1;
          return 0;
        });
        this.updated.emit('success');
      });
  }
异步getAllApplications(消息:any[],应用程序详细信息:any[]){ this.http.get(environment.serverTMODowntime+/tmodowntime.v1/downth/apps/all',{headers:this.headers}) .订阅((res:any[])=>{ message.length=0; appDetails.length=0; res.forEach(x=>{ 消息推送(x); x、 详细信息。forEach(y=>{ 常量appDetail={}; appDetail.createdDate=y.createdDate; appDetail.createdBy=y.createdBy; appDetail.updateDate=y.updateDate; appDetail.updatedBy=y.updatedBy; appDetails.push(appDetail); }); }); appDetails.sort((左侧、右侧)=>{ if(leftSide.startTimerighside.startTime)返回1; 返回0; }); this.updated.emit('success'); }); } 我希望对这两个数组(message和appDetails)的更改在调用组件代码时可见。但是,只显示对消息数组所做的更改(内部服务函数调用)。对appDetails数组的更改未显示在调用组件代码中

我无法解释为什么它在一个数组中以一种方式工作,而在第二个数组中以另一种方式工作


感谢您的帮助。

首先:检查您的x.details是否包含项目


第二:appDetail.startTime从未被指定值。因此,在sort函数中,比较null和null。这是一个错误。为appDetail.startTime指定一个值

谢谢。我检查了调试模式。当我们到达函数逻辑的末尾时,appDetails将填充少量行。我仍然有这个问题。此外,将appDetails更改为特定类型也没有帮助。是。当我在调试会话期间停止在emit行时,它填充了appDetails数组中的行。我在您的注释后编辑了答案,现在应该可以工作了。您在哪里“检查”该数组的内容?或者我应该问什么时候?您知道这是异步代码,对吗?Http调用是异步的。