具有双倍滚动内容的 Angular Material Sidenav

标签 angular angular-material mat-sidenav

对于基于 Angular Material 的项目,我正在尝试使用 sidenav具有不同 View 可能性的组件,具体取决于用户的设备(台式机或手机)。到目前为止它有效,但有一些问题。也就是说,内容一旦变长就会变成双倍滚动。

HTML 结构:

<mat-toolbar color="primary">
  <button mat-icon-button *ngIf="...">
    <mat-icon>menu</mat-icon>
  </button>
  Toolbar
</mat-toolbar>

<mat-sidenav-container>
  <mat-sidenav #sidenav ...>
    <mat-nav-list>
      <a mat-list-item (click)="closeSidenav()" routerLink="/item1">Item 1</a>
    </mat-nav-list>
  </mat-sidenav>

  <mat-sidenav-content class="content">
    <router-outlet></router-outlet>
    <footer>&copy; 2020 Lorem impsum. Dolor sit amet.</footer>
  </mat-sidenav-content>
</mat-sidenav-container>

mat-sidenav-content 元素上使用 overflow: hidden 等 CSS 操作来切断不可见的内容,并将其应用于 mat-sidenav- container 元素根本不会影响它。

这是一个StackBlitz Example

依赖版本:

  • @angular: 9.1.12
  • @angular/material: 9.2.4

那么,我做错了什么?有谁知道如何解决这一问题?或者在 Angular 项目中实现 sidenav + 工具栏的干净/更好的方法?任何帮助将不胜感激!

最佳答案

工具栏坚持 md-content 而不是 body -> 内部滚动条,就像 Angular Material 的网站一样,他们删除了主滚动条并使用:

body { overflow: hidden; max-width: 100%; max-height: 100%; } 

只保留内部的。

关于具有双倍滚动内容的 Angular Material Sidenav,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65038754/

相关文章:

javascript - Angular 如何在 IE9/10 中渲染自定义 html 标签而不让浏览器感到不安?

javascript - 在 Angular 2 中使用 *ngIf 或 *ngSwitchCase 时 View 发生变化

javascript - Angular Material 不触发滚动事件

javascript - 使用解析参数注入(inject) Controller

angular - 可折叠的 mat-sidenav 菜单调整内容大小不起作用

javascript - 我可以使用 Angular 日期管道格式化没有偏移量的时区吗?

Angular 4.3 HttpClient put 不触发

angular - 如何在 MD-selection-list Angular2 中设置选中元素的最大限制

angular - 使用 ViewChild 访问 MatDrawer 在 Angular 8 中抛出错误

angular - 无法从 Angular 中 mat-sidenav 内的组件检索路由参数