简体   繁体   English

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

[英]Angular nested `ngFor` using variable from outer loop

I am making a dynamic permissions list, how would I go about using the "item" from:我正在制作一个动态权限列表,我将如何使用以下“项目”:

<div *ngFor="let item of PermissionsList.T1">
  <!-- Some code here -->
</div>

in a inner ngFor loop.在内部ngFor循环中。 I have tried the following, and other similar variations:我尝试了以下以及其他类似的变化:

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

The PermissionsList example is like this: 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" ]

If PermissionsList is an Array of Arrays and you mean to iterate on the second arrays you can try this:如果PermissionsList是一个Array Arrays并且您的意思是迭代第二个数组,则可以尝试以下操作:

<div *ngFor="let permission of PermissionsList">
  <div *ngFor="let item of permission ">
    {{ item }}
  </div>
</div>

If PermissionsList is an Object of Arrays and you just want to display T1 for example, try this:如果PermissionsList是一个Arrays Object并且您只想显示T1例如,请尝试以下操作:

<div *ngFor="let t1 of PermissionsList['T1']">
  {{ t1 }}
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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