使用外循环中的变量的角度嵌套`ngFor`

时间:2020-09-17 20:50:51

标签: angular angular-ngfor

我正在制作一个动态权限列表,该如何使用来自以下位置的“项目”:

<div *ngFor="let item of PermissionsList.T1">
  <!-- Some code here -->
</div>
在内部ngFor循环中

。我尝试了以下方法和其他类似的方法:

<p *ngFor="let item2 of PermissionsList.{{item}}">test</p>

PermissionsList示例如下:

T1: Array [ "Business", "Recreation", "Vehicles" ]

Recreation: Array [ "Hunting", "Leisure" ]

Hunting: Array [ "Big_Game", "Bird", "Pest" ]

Big_Game: Array [ "Moose", "Elk" ]

​Pest: Array [ "Wild Boar", "Fox" ]

Bird: Array [ "Geese", "Sharp-tailed grouse" ]

​Leisure: Array [ "Hiking", "Bird Watching" ]

Business: Array [ "Trapping", "Utility", "Construction"]

Vehicles: Array [ "Half_ton", "ATV", "SnowMobile" ]

1 个答案:

答案 0 :(得分:1)

如果PermissionsListArray的{​​{1}},而您要遍历第二个数组,则可以尝试以下操作:

Arrays

如果<div *ngFor="let permission of PermissionsList"> <div *ngFor="let item of permission "> {{ item }} </div> </div> PermissionsList的{​​{1}},而您只想显示Object,请尝试以下操作:

Arrays