首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >除非设置了内容高度,否则不会显示Angular mat-sidenav

除非设置了内容高度,否则不会显示Angular mat-sidenav
EN

Stack Overflow用户
提问于 2021-04-05 22:23:51
回答 1查看 229关注 0票数 0

我试图让material侧边栏打开两个多小时,结果发现,如果没有在sidenav-content上设置高度,那么侧边栏根本就不会打开。我的目标是让侧边栏的高度总是在左侧,而不是内容所具有的相同高度。40vh的现状:SideNav not full height

有没有人知道为什么会这样,或者我的sidenav-content应该是与现在不同的东西?

代码语言:javascript
复制
    <app-header (toggleSidenav)="navigationSidenav.toggle()"></app-header>
    <mat-sidenav-container autosize="true">
      <mat-sidenav #navigationSidenav [fixedInViewport]="false">
        <mat-nav-list>
          <a mat-list-item [routerLink]="'/accounts'"> Accounts </a>
          <a mat-list-item [routerLink]="'/create-account'"> Create Account </a>
          <a mat-list-item [routerLink]="'/contacts'"> Contacts </a>
          <a mat-list-item [routerLink]="'/create-contact'"> Create Contact </a>
          <a mat-list-item [routerLink]="'/activities'"> Activities </a>
          <a mat-list-item [routerLink]="'/create-activity'"> Create Activity </a>
          <a mat-list-item (click)="navigationSidenav.toggle()">Close</a>
        </mat-nav-list>
      </mat-sidenav>
      <mat-sidenav-content>
        <div style="height: 40vh;">
          <router-outlet></router-outlet>
        </div>
      </mat-sidenav-content>
    </mat-sidenav-container>

应用标头如下所示

代码语言:javascript
复制
<mat-toolbar color="primary">
 <mat-toolbar-row>
    <button mat-icon-button (click)="toggleSidenav.emit()">
        <mat-icon>menu</mat-icon>
    </button>
  </mat-toolbar-row>
</mat-toolbar>
EN

回答 1

Stack Overflow用户

发布于 2021-04-06 00:15:27

官方文档:

默认情况下,<mat-sidenav>将适合其内容的大小。

因此,您应该显式地告诉组件期望的高度是多少。

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

https://stackoverflow.com/questions/66954553

复制
相关文章

相似问题

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