平均堆栈数据聚合,不显示 Angular

Mean Stack Data Aggregation, Not Displaying on Angular

我正在使用平均堆栈并在数据库中聚合数据以显示在前端。 我正在计算数据库集合的所有记录并返回要显示的数字。

但是我没有让它在 angular 前端工作:

聚合的控制器和路由器: 路线:

router.get('/DAFacilityCntRpts', DAFacilityController.DAFacility_count_reports)

控制器:

exports.DAFacility_count_reports = (req, res) => {
  DAFacility.aggregate([
    {
      '$project': {
        'eventName': 1, 
        'reportStatus': 1
      }
    }, {
      '$count': 'NoOfDaFacilityReports'
    }
  ]).then((DAFacility) => {
    res.send(DAFacility);
  })
  .catch((e) => {
    res.send(e);
  });
};

邮递员 returns 这个:

[
    {
        "NoOfDaFacilityReports": 4
    }
]

然而,当试图让该值显示在前端时,它并没有。 服务:

noOfDAFacReports() {
    return this._http.get("http://localhost:3000/DAFacilityCntRpts")
    .pipe(map((res:any)=>{
      return res;
    }))
  }

component.ts:

ngOnInit(): void {
    })
    console.log(this.aggregationFac)*/

    this.aggregation.noOfDAFacReports().subscribe(res=>
      {
        this.aggregationFac = res;
      })
  }

component.html:

<h3>Number of Facility Damage Assessment Reports Made: {{aggregationFac.NoOfDaFacilityReports}}</h3>

请让我知道哪里错了

这个问题已经在评论中解决了,就写在这里,方便以后的人找到。

MongoDB 始终聚合 returns 和 array,因此您将不得不使用

aggregationFac[0].NoOfDaFacilityReports

类型在 angular 中很有用,而不是使用 any