-2

第一个数组数据:

[
  { FirstName: "John", lastName: "Doe", Value: 46 },
  { FirstName: "Jack", lastName: "Smith", Value: 53 },
  { FirstName: "James", lastName: "Bhal", Value: true }
]

第二个数组舞会:

[
  { Label: "Ram", Key: "ram", Value: 46 },
  { Label: "Rom", Key: "rom", Value: 46 },
  { Label: "Mouse", Key: "mouse", Value: 46 }
]

如果第一个数组中的第三个对象值为假,如何在第二个数组中显示两个对象,如果第一个数组值中的第三个对象在角度 6 html 中为真,如何显示第二个数组中的所有对象。尝试使用*ngFor*ngIf

4

2 回答 2

0

在 ts 中,


firstArray = [
    { FirstName: "John", lastName: "Doe", Value: 46 },
    { FirstName: "Jack", lastName: "Smith", Value: 53 },
    { FirstName: "James", lastName: "Bhal", Value: false }
  ]

  secondArray = [
    { Label: "Ram", Key: "ram", Value: 46 },
    { Label: "Rom", Key: "rom", Value: 46 },
    { Label: "Mouse", Key: "mouse", Value: 46 }
  ]

在 html 中,

<div *ngFor="let item of secondArray;let i = index">
<div *ngIf="firstArray[2]?.Value === true || (firstArray[2]?.Value === false && i < 2)">{{ item | json }}</div>
</div>
于 2019-02-16T03:10:07.040 回答
0

hugomac的答案有效,但通过删除一些硬编码的值和不必要的值检查,它可以更可重用,方法boolean是:

<div *ngFor="let item of data2;let i = index">
  <div *ngIf="(data1[data1.length-1]?.Value) || ( !data1[data1.length-1]?.Value && i < (data1.length-1)) ">
    {{ item | json }}
  </div>
</div>

演示代码

于 2019-02-16T03:29:10.840 回答