角形mat-sidenav属性isHandset $ |异步解释 [英] Angular mat-sidenav property isHandset$ | async explain

查看:100
本文介绍了角形mat-sidenav属性isHandset $ |异步解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<mat-sidenav-container class="sidenav-container">
  <mat-sidenav #drawer class="sidenav" fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
    [mode]="(isHandset$ | async) ? 'push' : 'push'" [opened]="!(isHandset$ | async)">
    <mat-toolbar color="primary">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>

我不明白代码中写的是什么(isHandset$ | async)请解释

I do not understand what is written in the code (isHandset$ | async)please explain

推荐答案

手机"是角材料布局的断点名称之一.断点名称的列表是Handset,Tablet,Web,HandsetPortrait,TabletPortrait,WebPortrait,HandsetLandscape,TabletLandscape,WebLandscape.

'Handset' is one of the breakpoint names of angular material layout. The list of breakpoint names is Handset, Tablet, Web, HandsetPortrait, TabletPortrait, WebPortrait, HandsetLandscape, TabletLandscape, WebLandscape.

请检查 https://material.io/design/layout/响应-layout-grid.html#breakpoints 有关材质布局断点的更多信息

Please check https://material.io/design/layout/responsive-layout-grid.html#breakpoints for more information about material layout breakpoints

在上面的示例中,isHandset $来自相应的组件.ts文件.请在您的组件文件中查找与下面类似的代码.

In your example above, isHandset$ is coming from the corresponding component .ts file. Please look for code similar to below in your component file.

isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
    .pipe(
      map(result => result.matches)
    );

调整浏览器的大小以及浏览器的宽度与听筒(手机屏幕)匹配时,isHandset $的宽度将设置为true. (isHandset $ | async)依次将sidenav抽屉的'opened'属性设置为false并折叠sidenav抽屉.

When you resize the browser and when browser width matches with handset (mobile phone screen) width isHandset$ sets to true. ! (isHandset$ | async) in turn sets 'opened' attribute of sidenav drawer to false and collapses the sidenav drawer.

由于isHandset $是Observable属性,因此异步"管道用于异步调用.

As isHandset$ is an Observable property, therefore 'async' pipe is used for the asynchronous call.

这篇关于角形mat-sidenav属性isHandset $ |异步解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆