分类:
前端
先看看代码
export class SidenavComponent implements OnInit {
private mediaMatcher: MediaQueryList = matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`);
constructor(
private router: Router,
zone: NgZone) {
this.mediaMatcher.addListener(mql => zone.run(() => this.mediaMatcher = mql));
}
@ViewChild(MatDrawer) drawer: MatDrawer;
ngOnInit() {
this.router.events.subscribe(() => {
if (this.isScreenSmall()) {
this.drawer.close();
}
});
}
isScreenSmall(): boolean {
return this.mediaMatcher.matches;
}
}看着没什么错
实际根据版本的不同会有问题
(1)this未明确指明某对象
this.mediaMatcher.addListener(mql => zone.run(() => this.mediaMatcher = mql));
需改成
this.mediaMatcher.addListener(mql => {
zone.run((x) =>x.mediaMatcher = mql)
});(2)这里也是更具版本的不同也会遇到问题
@ViewChild(MatDrawer) drawer: MatDrawer;
需改成
@ViewChild(MatDrawer,{ static:true }) drawer: MatDrawer;后续会写一些Angluar多路由配置



欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
评价
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256
50010702506256
欢迎加群交流技术