将NGIF指令应用于< li>的最佳方法是什么.元素



我有这样的结构:

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>

如果我们不想备份ngifs int这个结构,该怎么办?

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

相关内容

最新更新