【发布时间】:2020-01-13 01:55:14
【问题描述】:
我正在关注这个视频 (https://www.youtube.com/watch?v=Q6qhzG7mObU) 教程,了解如何使用工具栏设置 Angular Material Sidenav,但它似乎只有在我调整页面大小后才会生效。不知道是不是我的小问题,还是我漏掉了什么小问题。
Doesn't show the menu icon on page load (even if page starts on mobile size)
Shows menu icon as soon as page resizes to a mobile size
import { Component } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { map, share } from 'rxjs/operators';
@Component({
selector: 'app-nav-bar',
templateUrl: './nav-bar.component.html',
styleUrls: ['./nav-bar.component.css']
})
export class NavBarComponent {
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
.pipe(
map(result => result.matches),
share()
);
constructor(private breakpointObserver: BreakpointObserver) {}
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="(isHandset$ | async) === false">
<mat-toolbar>Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</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>ProjectVAS</span>
</mat-toolbar>
<!-- Add Content Here -->
</mat-sidenav-content>
</mat-sidenav-container>
.sidenav-container {
justify-content: space-between;
height: 100%;
}
.sidenav {
width: 150px;
}
它必须只显示菜单按钮(或页面加载的一侧)
【问题讨论】:
标签: html css node.js angular angular-material