带有垫子扩展面板的Angular 6 mat-nav-list

时间:2019-03-13 09:46:28

标签: angular angular-material angular6 angular-material2 angular-material-6

我正在尝试创建一个包含mat-expansion-panels作为列表项的mat-nav-list。 问题是mat-nav-list不能按预期工作,对齐混乱,扩展面板无法正常工作。我认为,发生这种情况是因为mat-nav-lists不支持mat-expansion-panels作为列表项。(如果我错了,请纠正我)enter image description here

我的html代码如下

<mat-nav-list>
    <mat-list-item>
    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>
          Personal data
        </mat-panel-title>
        <mat-panel-description>
          Type your name and age
        </mat-panel-description>
      </mat-expansion-panel-header>
      <mat-form-field>
        <input matInput placeholder="First name">
      </mat-form-field>
      <mat-form-field>
        <input matInput placeholder="Age">
      </mat-form-field>
    </mat-expansion-panel>
  </mat-list-item>

  <mat-list-item>
    <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-list-item>
</mat-nav-list>

如果有人可以为我提供解决此问题的方法,我将不胜感激。

2 个答案:

答案 0 :(得分:1)

除了使用mat-list-item之外,还可以对div的for循环进行迭代,并且可以同样添加扩展面板

<div *ngFor="let hero of herolist">
   <mat-expansion-panel>
    // here you can do whateever you want
   </mat-expansion-panel>
</div>

如果您想用sidenav实现它,可以拥有它

<ng-container>
    <mat-side-nav>
    </mat-side-nav>
</ng-container>

答案 1 :(得分:0)

也许您想将扩展面板嵌套在垫子手风琴中?

<mat-accordion>
  <mat-expansion-panel></mat-expansion-panel>
  <mat-expansion-panel></mat-expansion-panel>
</mat-accordion>

https://material.angular.io/components/expansion/overview#accordion