[英]mat-sidenav-container breakpoint override
I am using a mat-sidenav-container 我正在使用垫-sidenav容器
Is there a way to override the breakpoint so the drawer does not automatically open when the screen gets to a certain width? 有没有一种方法可以覆盖断点,以便在屏幕达到一定宽度时不会自动打开抽屉?
Under 600 px - shows hamburger 低于600像素-显示汉堡
Currently @ 600px it opens automatically 当前@ 600px,它会自动打开
I only want it to open if the user clicks on the hamburger 我只想在用户单击汉堡包时将其打开
Over 600px - Stays open 超过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>
In the .ts 在.ts中
isHandset$: Observable<boolean> =
this.breakpointObserver.observe(Breakpoints.Handset)
.pipe(
map(result => result.matches)
);
Of course, you figure it out right after you post the question 当然,您可以在发布问题后立即解决
Hard coding the attributes seems to do the trick 硬编码属性似乎可以解决问题
Instead of using the isHandset$ observable that watches the breakpoints 而不是使用观察断点的isHandset $ observable
attr.role="dialog"
mode="over"
opened="false"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.