Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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 将ngif指令应用于<;李>;元素?_Angular_Angular6_Angular5 - Fatal编程技术网

Angular 将ngif指令应用于<;李>;元素?

Angular 将ngif指令应用于<;李>;元素?,angular,angular6,angular5,Angular,Angular6,Angular5,我有一个这样的结构: class GrandParent{ childsOfGrandParent: Parent[]; } class Parent{ child: Child; } class Child{ x:number y:number z:number } 如果在.ts中有这样的对象 grandParent: GrandParent[] = []; 和html格式: <ul *ngFor="let parent of grandParent.child

我有一个这样的结构:

class GrandParent{
  childsOfGrandParent: Parent[];
}

class Parent{
  child: Child;
}

class Child{
 x:number
 y:number
 z:number
}
如果在.ts中有这样的对象

  grandParent: GrandParent[] = [];
和html格式:

<ul *ngFor="let parent of grandParent.childsOfGrandParent; let i = index;">

      <li  *ngIf="parent.child"> 
           {{child.x}}</li>
      <li  *ngIf="parent.child"> 
           {{child.y}}</li>
      <li  *ngIf="parent.child"> 
           {{child.z}}</li>

    </ul>


{{child.x}

{{child.y}

{{child.z}

如果我们不想重新绘制此结构,我该怎么办?


<ng-container *ngIf="parent.child">
      <li>{{child.x}}</li>
      <li>{{child.y}}</li>
      <li>{{child.z}}</li>
</ng-container>
  • {{child.x}
  • {{child.y}
  • {{child.z}

  • …我已经应用了这个,我正在寻找更合适的方法。我不想为每个
  • elements@Ozmen没问题,考虑接受一个答案来结束你的问题(如果我的答案对你有帮助,请投我的一票)