angular - 如何以角度选择具有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>
可能吗?
解决方案
使用结构指令 ngFor,然后使用索引
<ul>
<li *ngFor="let item of items; let i = index">
{{i}} {{item}}
</li>
推荐阅读
- java - Java如何在终端中动态更改数字
- javascript - MongoDB BSON 文档大小异常
- typescript - 为什么不能推断出这些泛型类型?
- c# - 将 Wireshark 过滤器表达式转换为 BPF
- c# - 带有 ASP.NET 4.6.2 Web API 的 Identity Server 4 导致重定向
- linux - awk 'FNR == 2 {print}' 问题
- python - 使用飞行写表时出现“OSError:无法将记录批处理写入流”
- javascript - 如何添加警报 angular11
- python - Neomodel:在连接字符串中指定 neo4j 数据库名称
- node.js - 定期增加与需要值时更新