【问题标题】:Adding NgFor breaking Mat-line flex in angular 9添加 NgFor 在角度 9 中破坏 Mat-line flex
【发布时间】:2021-09-09 05:36:41
【问题描述】:

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

但是当我添加 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

【问题讨论】:

    标签: angular bootstrap-4 angular-material ngfor mat-list


    【解决方案1】:

    使用

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

    点击here查看代码

    【讨论】:

    • 我已经修改了答案
    猜你喜欢
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 2012-11-01
    • 2018-10-03
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多