Angular 角度,REST-API Json对象,使用子对象访问特定数组

Angular 角度,REST-API Json对象,使用子对象访问特定数组,angular,typescript,rxjs,Angular,Typescript,Rxjs,我有以下问题在我的角度项目。我从API中获得以下数据(示例数据): { "plant": [ { "workplateId": 0, "workplaceTypeId": 0, "description": "string", "aktiveOrder": 0, "spsActive": true, "plantActive": true, "plantStatus": 0, "o

我有以下问题在我的角度项目。我从API中获得以下数据(示例数据):

    {
  "plant": [
    {
      "workplateId": 0,
      "workplaceTypeId": 0,
      "description": "string",
      "aktiveOrder": 0,
      "spsActive": true,
      "plantActive": true,
      "plantStatus": 0,
      "orderManagementActive": true,
      "Cycle": 0
    },
    {
      "workplateId": 1,
      "workplaceTypeId": 0,
      "description": "string",
      "aktiveOrder": 0,
      "spsActive": false,
      "plantActive": false,
      "plantStatus": 0,
      "orderManagementActive": true,
      "Cycle": 0
    }
  ],
  "productFig": {
    "earlyShift": [
      {
        "plantId": 0,
        "shiftId": "string",
        "quant101": 0,
        "sqm101": 0,
        "quant531": 0,
        "sqm531": 0,
        "quant532": 0
      },
      {
        "plantId": 1,
        "shiftId": "string",
        "quant101": 100,
        "sqm101": 1000,
        "quant531": 0,
        "sqm531": 0,
        "quant532": 0
      }
    ],
    "lateShift": [
      {
        "plantId": 0,
        "shiftId": "string",
        "quant101": 0,
        "sqm101": 0,
        "quant531": 0,
        "sqm531": 0,
        "quant532": 0
      },
      {
        "plantId": 1,
        "shiftId": "string",
        "quant101": 2000,
        "sqm101": 20000,
        "quant531": 0,
        "sqm531": 0,
        "quant532": 0
      }
    ],
    "nightShift": [
      {
        "plantId": 0,
        "shiftId": "string",
        "quant101": 0,
        "sqm101": 0,
        "quant531": 0,
        "sqm531": 0,
        "quant532": 0
      }
    ]
  }
}
Iam将类型数据[]中的数据存储在属性中。数据类型是一个接口。这样做没有问题,我可以在我的组件中访问整个数据。ts:

 this.store.pipe(select(getAllData)).
     subscribe(data => {
       this.data = data;
      console.log(data);
     });
但是,当我尝试在html中访问它时,会出现以下错误:

错误:尝试区分“[object]”时出错。只允许使用数组和iterables

我的实施是:

<ov-plant *ngFor="let p of data"></ov-plant>

我需要从datta访问plant数组,因此第一个数组来自数据。这对你们来说可能是个简单的问题,但我希望有人能帮我一把:)


提前谢谢

您必须将
此.data
设置为所讨论的数组

尝试:


您必须将
this.data
设置为相关数组

尝试:


这是因为您的数据是一个对象,您不能遍历对象。 您需要在其中指定一个数组。例如:

<ov-plant *ngFor="let p of data['plant']"></ov-plant>

这是因为您的数据是一个对象,不能遍历对象。 您需要在其中指定一个数组。例如:

<ov-plant *ngFor="let p of data['plant']"></ov-plant>

您可以通过Pull加入数据阵列。您将保留所有类型信息,并且不必在html中执行任何逻辑

this.store.pipe(
  select(getAllData),
  pluck('plant')
).subscribe(value => this.data = value);

您可以通过Pull加入数据阵列。您将保留所有类型信息,并且不必在html中执行任何逻辑

this.store.pipe(
  select(getAllData),
  pluck('plant')
).subscribe(value => this.data = value);

工作起来很有魅力!有时候我们只是瞎了眼。非常感谢。工作起来很有魅力!有时候我们只是瞎了眼。非常感谢。您的
data
变量是一个对象,但
ngFor
需要一些可以迭代的东西。请尝试
*ngFor=“let p of data.plant”
您的
数据
变量是一个对象,但
ngFor
需要可以迭代的东西。请尝试
*ngFor=“让p离开data.plant”