angular - ngFor 停止自动换行
问题描述
无论如何要停止将每个元素放在新行上的 ngFor 循环?
这是我现在拥有的代码
<div class="groups">
<h3>Groups:</h3>
<div *ngFor="let group of groups; let i = index" class="group">
<button (click)="changeGroup(i)">{{group}}{{i}}</button>
</div>
</div>
产生这个
如何使按钮出现在同一行?
解决方案
ngFor
循环在元素div
上。由于这些是块元素,因此您最终会得到一堆垂直的div
容器,每个容器都包含一个按钮。
要获得一个包含所有按钮的块,请将ngFor
循环放在button
元素上:
<div class="groups">
<h3>Groups:</h3>
<div class="group">
<button *ngFor="let group of groups; let i = index" (click)="changeGroup(i)">{{group}}{{i}}</button>
</div>
</div>
推荐阅读
- android - 可以为 TimePicker 使用已弃用的主题吗
- amazon-web-services - 我如何输出 IAM 角色并在另一个堆栈中使用它?
- jenkins - Jenkins 和 Kubernetes 集成使用 Helm
- azure-virtual-network - Azure 站点到站点 TrafficSelectorPolicy 不起作用
- c# - 无法使冷却工作,出现错误并且无法正常工作
- java - 如何保护 Arraylist 免受逆向工程
- c# - ASP.NET Core 标识用户组
- python - Anaconda 与 IBM 沃森工作室
- python - 如何在 Jupyter notebook 中使用 pandas 修改 CSV 格式数据?
- java - 在 Amazon s3 上传的视频中检测人脸时,SQSMessageSuccess 没有响应