简体   繁体   English

如何选择角度为ng的第n个孩子

[英]How to select the nth child with ng-content in angular

I want to be able to select the children by their position. 我希望能够根据他们的位置选择孩子。 For example: 例如:

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

Is it possible? 可能吗?

Use structural directive ngFor and then work with index 使用结构指令ngFor,然后使用索引

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

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

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