简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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