简体   繁体   中英

Getting the data of the object in Angular Object

I have an object as you have seen below, I want to get the data called measurementPointName from the measurement tables contained in this object, how can I print it to the screen using angular.

enter image description here

I tried *ngFor="let x of measurementTableList" but unfortunately it didn't work.

You'll need two *ngFor, one to cicle the "general array" of 2 elements and then one to cicle on measurementTableCalculations.

Into the second ngFor, you have to select the name field, so:

1: *ngFor="let SINGLE_ARRAY_ELEMENT of GENERAL_ARRAY_VARIABLE_NAME"

Assuming GENERAL_ARRAY_VARIABLE_NAME = worksList, you'll have: *ngFor="let work of worksList" and this is your first div

into that, you have to go for 2: *ngFor="let measurementTableCalculation of work.measurementTableCalculations" and print the field measurementTableCalculation.name where you want it, so:

{{ measurementTableCalculation.name }}

Your data returned as an array. You can access the data in the second index.

// your data
apiResult = [
  {
    workOderId: 1234
    ...
  },
  {
    measurementTableList: [
      ...
    ]
  }
];

you then can acces the needed data by either putting the second index in different variable or just do:

<div *ngFor="let x of apiResult[1].measurementTableList" ></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM