Adding NgFor breaking Mat-line flex in angular 9

204 Views Asked by At

I need to display like the example below

enter image description here

BUT when i add ngfor it breaks mat line flex row in to column.

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]
}
}
]}

Working example code here Slackblitz.example

1

There are 1 best solutions below

1
On BEST ANSWER

use

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

instead of

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

click here to view code