首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular 5展开/折叠列表

Angular 5展开/折叠列表
EN

Stack Overflow用户
提问于 2018-02-08 22:23:55
回答 2查看 19.7K关注 0票数 2

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

代码语言:javascript
复制
 <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控件上实现点击功能?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-08 23:00:39

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

它看起来是这样的:

代码语言:javascript
复制
<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>
票数 6
EN

Stack Overflow用户

发布于 2018-02-08 22:26:41

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48687758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档