【问题标题】:How can I open multi-panel using Expansion panel of angular material?如何使用角材料的扩展面板打开多面板?
【发布时间】:2021-09-27 08:29:37
【问题描述】:

我想使用扩展面板,结果我想打开多个面板,比如这个例子: open example

这是我的代码:

<mat-accordion>
  <mat-expansion-panel hideToggle>
    <mat-expansion-panel-header>
      <mat-panel-title>
        This is the expansion title
      </mat-panel-title>
      <mat-panel-description>
        This is a summary of the content
      </mat-panel-description>
    </mat-expansion-panel-header>
    <p>This is the primary content of the panel.</p>
  </mat-expansion-panel>
  <mat-expansion-panel (opened)="panelOpenState = true"
                       (closed)="panelOpenState = false">
    <mat-expansion-panel-header>
      <mat-panel-title>
        Self aware panel
      </mat-panel-title>
      <mat-panel-description>
        Currently I am {{panelOpenState ? 'open' : 'closed'}}
      </mat-panel-description>
    </mat-expansion-panel-header>
    <p>I'm visible because I am open</p>
  </mat-expansion-panel>
</mat-accordion>

【问题讨论】:

  • 很难理解您到底想要实现什么,您能否澄清问题,并提供一些不起作用的代码?代码示例是来自material.angular.io/components/expansion/… 的copypasta
  • 以下 stackblitz 提供了嵌套垫扩展面板的最小示例stackblitz.com/edit/…
  • @Simplicity's_Strength 是的!因为我不知道如何在有角度的材料中编辑代码,所以我想要的是当我单击面板中的箭头时,我想打开卡片(多个),就像它在示例中显示的那样(请检查链接)跨度>

标签: html angular angular-material panel expansion


【解决方案1】:

请考虑以下stackblitz

在子扩展面板上添加 hideToggle disabled 有助于匹配链接的图片,使用了两个 mat-accordions,第二个具有 multi允许打开多个面板的属性

<mat-accordion>
  <mat-expansion-panel class="parentPanel" [expanded]="true">
    <mat-expansion-panel-header class="parentPanel_header">
      <mat-panel-title> Group </mat-panel-title>
    </mat-expansion-panel-header>
    <mat-accordion multi>
      <mat-expansion-panel class="childPanel childPanelCount" [expanded]="true" hideToggle disabled>
        <p>Elements count {{elements.length}}</p>
      </mat-expansion-panel>
      <ng-container *ngFor="let i of elements">
        <mat-expansion-panel class="childPanel" [expanded]="true" hideToggle disabled>
          <p>Element</p>
        </mat-expansion-panel>
      </ng-container>
    </mat-accordion>
  </mat-expansion-panel>
</mat-accordion>

需要一些 css 来实现匹配的外观,尽管这不是 css 问题

mat-expansion-panel.parentPanel {
  box-shadow: none;
  background-color: transparent;
}
.parentPanel_header {
  background-color: white;
  border: 1px solid lightgray;
  box-shadow: 0px 3px 1px -2px rgba(0, 0, 0, 0.2),
    0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12);
}
.childPanelCount{
  opacity: 50%;
}

.parentPanel mat-expansion-panel.childPanel {
  margin-top: 1em !important;
}

::ng-deep .childPanel div.mat-expansion-panel-body {
  padding-bottom: 0 !important;
}

【讨论】:

  • 非常感谢
  • 仍然必须动态地转动它.. Je suis encore débutante c'est pourquoi j'ai essayé de chercher des Solutions sur google , stackoverflow pour apprendre .... en tt cas merci beaucoup !跨度>
猜你喜欢
  • 2018-03-23
  • 1970-01-01
  • 2021-04-11
  • 2019-03-15
  • 2018-10-10
  • 2018-06-26
  • 1970-01-01
  • 2018-03-14
  • 2020-04-19
相关资源
最近更新 更多