Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用ngFor在JSON中打印子值_Angular - Fatal编程技术网

Angular 使用ngFor在JSON中打印子值

Angular 使用ngFor在JSON中打印子值,angular,Angular,我想使用一些具有父属性和子属性的JSON数据来显示一个包含父子内容的手风琴 在app.component.html中使用ngFor时,当手风琴展开时,仅打印第一个子属性,而不是所有子属性。另外,我希望文本框在每个手风琴面板中都有一个唯一的id 检查 将*ngFor放在p标记而不是div中,它有panel类,这会导致显示子项时出现问题 <div *ngFor="let item of data;let i = index;"> <button class="accordion

我想使用一些具有父属性和子属性的JSON数据来显示一个包含父子内容的手风琴

在app.component.html中使用ngFor时,当手风琴展开时,仅打印第一个子属性,而不是所有子属性。另外,我希望文本框在每个手风琴面板中都有一个唯一的id

检查

将*ngFor放在p标记而不是div中,它有panel类,这会导致显示子项时出现问题

<div *ngFor="let item of data;let i = index;">
  <button class="accordion" (click)="toggleAccordian($event, i)"> {{item.parentName}} </button>
  <div class="panel" hide="!item.isActive">
    <input type="text">
    <p *ngFor="let child of item.childProperties"> {{child.propertyName}} </p>
  </div>
</div>

可能重复这不是ngFor的问题。所有元素都已正确渲染,但不可见。除了不应该在angular中操作DOM之外,您只修改了切换父元素内的第一个.panel的maxHeight。好的。。谢谢这是有道理的。我会尝试另一种方法来渲染手风琴。是的。顺便说一句,这些隐藏属性也是无用的。请将所有相关代码包含在一个here-on-Stack溢出中,而不仅仅是在一个外部站点上。