【发布时间】:2018-09-23 22:18:39
【问题描述】:
我正在使用 mat-sidenav-container
有没有办法覆盖断点,所以当屏幕达到一定宽度时抽屉不会自动打开?
目前@600px 它会自动打开
我只希望它在用户点击汉堡时打开
超过 600 像素 - 保持打开状态
<mat-sidenav-container class="sidenav-container">
<mat-sidenav
#drawer
class="sidenav"
fixedInViewport="false"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="!(isHandset$ | async)">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-nav-list *ngFor="let i of navItems">
<a *ngIf="(i.navText) && (i.router) && (i.showYNNav === 'Y')"
mat-list-item [routerLink]="[i.router]">{{i.navText}}</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<button
type="button"
aria-label="Toggle sidenav"
mat-icon-button
(click)="drawer.toggle()"
*ngIf="isHandset$ | async">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<span>
<a class="mat-toolbar mat-primary homeLink"
[routerLink]="['/']"
routerLinkActive="active"
[routerLinkActiveOptions]="{exact: true}">
<span>Site Name Here</span>
</a>
</span>
</mat-toolbar>
<div class="componentMargin">
<router-outlet #outlet="outlet"></router-outlet>
</div>
<app-footer></app-footer>
</mat-sidenav-content>
</mat-sidenav-container>
在.ts中
isHandset$: Observable<boolean> =
this.breakpointObserver.observe(Breakpoints.Handset)
.pipe(
map(result => result.matches)
);
【问题讨论】:
-
可以分享一下代码吗?
-
分享你的 html 和 typescript 会有很大帮助