Angular 如何在不使用ngFor的情况下遍历json结果

Angular 如何在不使用ngFor的情况下遍历json结果,angular,Angular,我有一个JSON结果,我从后端得到它,它给我以下结果 [ { "status":"RUN", "numberOfTurbines":1 }, { "status":"ERROR", "numberOfTurbines":20 }, { "status":"ST

我有一个JSON结果,我从后端得到它,它给我以下结果

[
   {
      "status":"RUN",
      "numberOfTurbines":1
   },
   {
      "status":"ERROR",
      "numberOfTurbines":20
   },
   {
      "status":"STOP",
      "numberOfTurbines":5
   },
   {
      "status":"START_UP",
      "numberOfTurbines":2
   }
]
我有4张带有图标的卡,指示我的ts组件中的每个状态(运行、错误、停止、启动):

this.service.getAllTurbinesStat().subscribe(s=>{
  this.allStats = s;
});
在我的html中:


跑
盘形工具
错误
建立循环
停止
箭头\圆圈\向下
启动

我只想获得各自的数据并放入每张卡中,我如何实现?*Ng因为我知道要通过数据,但我如何获得我想要的字段数据?涡轮机的数量和状态

为什么不使用
*ngFor

const=[]//您的JSON对象数组

状态:{{turbine.Status}

涡轮机:{{turbine.numberofturbins}


为什么不使用
*ngFor

const=[]//您的JSON对象数组

状态:{{turbine.Status}

涡轮机:{{turbine.numberofturbins}


如果您确定只会获得此数据。然后根据状态(非必需)对结果进行排序,并通过索引显示数据。例如。this.allStats[0]。status将返回RUN,this.allStats[0]。numberOfTurbines将返回1。@HPSingh我不需要ngFor吗?是的,你不需要ngFor。您将按索引从数组“this.allStats”中获取数据。@SamScholefield的答案看起来正确。如果您确定只获取此数据。然后根据状态(非必需)对结果进行排序,并通过索引显示数据。例如。this.allStats[0]。status将返回RUN,this.allStats[0]。numberOfTurbines将返回1。@HPSingh我不需要ngFor吗?是的,你不需要ngFor。您将按索引从数组“this.allStats”中获取数据。@SamScholefield的答案看起来正确。