首页 > 解决方案 > 如何以角度选择具有ng-content的第n个孩子

问题描述

我希望能够根据他们的位置来选择孩子。例如:

<ul>
  <li>
    <ng-content select=":nth-child(1)"></ng-content>
  </li>
  <li>
    <ng-content select=":nth-child(2)"></ng-content>
  </li>
</ul>

可能吗?

标签: angular

解决方案


使用结构指令 ngFor,然后使用索引

<ul>
  <li *ngFor="let item of items; let i = index">
  {{i}} {{item}}
</li>


推荐阅读