如何为非li元素应用ngfor?

问题描述 投票:0回答:2

一旦条件满足,我正在尝试循环一组数据,我正在显示一个标签但是它在标签前面的添加空间因为我用于ngfor的div。如何在没有空格的情况下实现显示文本。下面是我正在尝试的示例

'<div  *ngFor="let rows of list"   >

     <label  *ngIf="list.name == 'test'"  >Confirm </label>
      <strong>{{list.name}}</strong> 


    <label *ngIf="rows.name != 'test' ">dont Confirm
 <strong>{{list.name}}</strong> 
</label>
</div>'
angular angular6 angular2-directives ngfor
2个回答
0
投票

你可以使用ng-container或使用CSS删除div的间距:)


0
投票
<div  *ngFor="let rows of list"   >

 <label  *ngIf="list.name == 'test'"  >Confirm </label>

您的示例中必定存在错误,在ngFor列表中必须是数组。数组如何具有名称属性?保存数组的变量的名称是“list”。另外,我不会像这样命名“行”,这很令人困惑,只需将其命名为“row”即可。

https://angular.io/guide/template-syntax#ngFor

© www.soinside.com 2019 - 2024. All rights reserved.