【问题标题】:Angular 5 Expand/Collapse listAngular 5 展开/折叠列表
【发布时间】:2019-06-02 20:54:49
【问题描述】:

我使用材质列表控件来显示嵌套对象。我用 div 创建了 mat 列表,但我想在此处添加展开/折叠行选项,当我单击行时,它应该显示子类别 div ?

 <mat-list>
    <div *ngFor="let item of chaptersItems">
        <mat-list-item>
            <a style="cursor: pointer;">
                <h4 mat-line>{{item.name}}    {{item.description}}</h4>
            </a>
        </mat-list-item>
        <mat-list style="margin-left:30px;">
            <div *ngFor="let subItem of item.subChapters">
                <mat-list-item>
                    <a style="cursor: pointer;">
                        <p mat-line> {{subItem.name}}. {{subItem.description}}</p>
                    </a>
                </mat-list-item>
            </div>
        </mat-list>
    </div>
</mat-list>

如何在 div 或 mat-list 控件上实现点击功能?

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    您可以将每个项目包装到 mat-expansion-panel 包装器中,如下所述: https://material.angular.io/components/expansion/overview

    看起来像这样:

    <mat-list>
        <div *ngFor="let item of chaptersItems">
        <mat-expansion-panel>
                <mat-expansion-panel-header>
                    <mat-list-item>
                        <a style="cursor: pointer;">
                            <h4 mat-line>{{item.name}}    {{item.description}}</h4>
                        </a>
                    </mat-list-item>
                <mat-expansion-panel-header>
                <mat-list style="margin-left:30px;">
                    <div *ngFor="let subItem of item.subChapters">
                        <mat-list-item>
                            <a style="cursor: pointer;">
                                <p mat-line> {{subItem.name}}. {{subItem.description}}</p>
                            </a>
                        </mat-list-item>
                    </div>
                </mat-list>
            </mat-expansion-panel>
        </div>
    </mat-list>
    

    【讨论】:

    • 完美就是这样。谢谢
    • 第二个标签应该是一个结束标签:
    【解决方案2】:

    您可以使用Expansion 组件,它非常简单

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 2010-12-03
      相关资源
      最近更新 更多