0

我需要像下面的例子一样显示

在此处输入图像描述

但是当我添加 ngfor 时,它会将 mat line flex 行中断到列中。

HTML

<mat-list *ngFor="let list of lists">
<mat-list-item *ngFor="let car of list.cars | keyvalue">
<h3 mat-line> {{car.key}} </h3>
<p mat-line *ngFor="let year of car.value">
<span> {{year}} </span>
</p>
<button mat-icon-button >
<mat-icon class="mat-24">delete</mat-icon>
</button>
</mat-list-item>
</mat-list>

TS

export class ListSelectionExample {
lists = [
{
"cars":
{
 "12345": [1960, 1961],
 "4567": [2001, 2002]
}
}
]}

工作示例代码在这里 Slackblitz.example

4

1 回答 1

0

采用

 <p mat-line >
    <span *ngFor="let year of car.value; let i = index"> {{year}}{{i==0?',':''}} </span>
  </p>

代替

<p mat-line *ngFor="let year of car.value">
<span> {{year}} </span>
</p>

点击这里查看代码

于 2021-06-25T22:51:25.217 回答