gpt4 book ai didi

html - ngFor 循环中的换行符

转载 作者:太空狗 更新时间:2023-10-29 17:41:53 24 4
gpt4 key购买 nike

我有一个 ngFor 可以创建多个 PrimeNG 按钮。现在,这些按钮紧接着出现在同一行上——我希望每个按钮都垂直显示在其线上。你是怎么做到的?这是我的 ngFor 代码:

<button pButton type="button" 
*ngFor="let atrConfig of atrConfigs; let i = index"
(click)="selectConfiguration(atrConfig)" label = "">
Name: {{atrConfig.name}} <br />
</button>

最佳答案

您应该使用 ng-container 标签来对元素进行分组,但不会在 DOM 树中作为节点呈现。

<ng-container *ngFor="let atrConfig of atrConfigs; let i = index" >
<button pButton type="button"
(click)="selectConfiguration(atrConfig)" label = ""> Name: {{atrConfig.name}}
</button>
<br />
</ng-container>

在此示例中,使用 CSS 可能同样简单,但如果您不想要周围的 div,则 ng-container 会非常有用,例如填充表格

关于html - ngFor 循环中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41941996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com