Angular 学习笔记 ( CDK - Layout )
简单说就是 js 的 media query.
1. BreakpointObserver
const layoutChanges = this.breakpointObserver.observe([
'(orientation: portrait)',
'(orientation: landscape)',
]); layoutChanges.subscribe(result => {
updateMyLayoutForOrientationChange();
});
ng 还包装了一个 observe 方便我们监听 view port 的变化.
此外 ng 也依据 material 的标准提供了一个 enum 方便我们写匹配.
export const Breakpoints = {
Handset: '(max-width: 599px) and (orientation: portrait), ' +
'(max-width: 959px) and (orientation: landscape)',
Tablet: '(min-width: 600px) and (max-width: 839px) and (orientation: portrait), ' +
'(min-width: 960px) and (max-width: 1279px) and (orientation: landscape)',
Web: '(min-width: 840px) and (orientation: portrait), ' +
'(min-width: 1280px) and (orientation: landscape)',
HandsetPortrait: '(max-width: 599px) and (orientation: portrait)',
TabletPortrait: '(min-width: 600px) and (max-width: 839px) and (orientation: portrait)',
WebPortrait: '(min-width: 840px) and (orientation: portrait)',
HandsetLandscape: '(max-width: 959px) and (orientation: landscape)',
TabletLandscape: '(min-width: 960px) and (max-width: 1279px) and (orientation: landscape)',
WebLandscape: '(min-width: 1280px) and (orientation: landscape)',
};
2. MediaMatcher
这个是底层服务,breakpoint 就是建立在这个之上的.
它没有 observe 只能单纯匹配 media query, 而它的实现原理就是调用了 dom api Window.matchMedia.
所以到这里可以体会到, cdk 帮我们解决了调用 dom api 的烦恼. 写 ui 组件操作 dom 是必然的. 而兼容跨平台问题也是必然的.
cdk 的目的就是要减轻我们这方面的麻烦.
Angular 学习笔记 ( CDK - Layout )的更多相关文章
- Angular 学习笔记 ( CDK - Accessibility )
@angular/ckd 是 ng 对于 ui 组建的基础架构. 是由 material 团队开发与维护的, 之所以会有 cdk 看样子是因为在开发 material 的时候随便抽象一个层次出来给大家 ...
- Angular 学习笔记 ( CDK - Portal )
Portal 的主要使用场景是 dynamic component 动态的插入模板或组件. Portal 可分为 2 种. 进入和出去 (in or out) ComponentPortal, Tem ...
- Angular 学习笔记 (cdk focus monitor 和一些 focus tabindex 的基础)
更新 : 2019-12-22 focusInitialElementWhenReady 我们经常会调用到这个方法, 它的逻辑是这样 先看有没有 cdkFocusInitial 有的就 focus ...
- Angular 学习笔记 ( CDK - Overlays )
更新 : 2018-01-30 ng 的 overlap 在关闭的时候对 backdrop 做了一个 style pointer 目的是让 backdrop 不被 2 次点击, 但是呢, css p ...
- Angular 学习笔记 ( CDK - Observers )
<div class="projected-content-wrapper" (cdkObserveContent)="projectContentChanged( ...
- angular学习笔记(三十一)-$location(2)
之前已经介绍了$location服务的基本用法:angular学习笔记(三十一)-$location(1). 这篇是上一篇的进阶,介绍$location的配置,兼容各版本浏览器,等. *注意,这里介绍 ...
- angular学习笔记(三十一)-$location(1)
本篇介绍angular中的$location服务的基本用法,下一篇介绍它的复杂的用法. $location服务的主要作用是用于获取当前url以及改变当前的url,并且存入历史记录. 一. 获取url的 ...
- angular学习笔记(三十)-指令(10)-require和controller
本篇介绍指令的最后两个属性,require和controller 当一个指令需要和父元素指令进行通信的时候,它们就会用到这两个属性,什么意思还是要看栗子: html: <outer‐direct ...
- angular学习笔记(三十)-指令(7)-compile和link(2)
继续上一篇:angular学习笔记(三十)-指令(7)-compile和link(1) 上一篇讲了compile函数的基本概念,接下来详细讲解compile和link的执行顺序. 看一段三个指令嵌套的 ...
随机推荐
- PAT乙级-1043. 输出PATest(20)
给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按"PATestPATest...."这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一 ...
- 数据定义: CREATE、DROP、ALTER
CREATE DATABASE 句法 CREATE DATABASE [IF NOT EXISTS] db_name 数据库.表.索引.列和别名 中被给出. 如果数据库已经存在,并且你没有指定 IF ...
- Javscript的函数链式调用基础篇
我们都很熟悉jQuery了,只能jQuery中一种非常牛逼的写法叫链式操作: $('#div').css('background','#ccc').removeClass('box').stop(). ...
- MYSQL数据库学习六 索引的操作
6.1 索引 由于数据存储在数据库表中,所以索引是创建在数据库表对象上的,由表中的一个或多个字段生成的键组成,这些键存储在数据结构(B-树或哈希表)中,通过索引可以快速有效地查找与键值相关联的字段.根 ...
- 【Python】 配置文件相对路径&软件自动执行的工作目录
今天对监控脚本做了一些变更,然后突然发现监控全部都失效了..排查了半天问题仍然不知所踪.最终发现居然是一个踩过好几次的老坑.. 就是脚本内写的配置文件为了调试方便写成了相对路径,但是在上线时没有意识到 ...
- LeetCode --> 771. Jewels and Stones
Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...
- Algorithm --> 顺序打印矩阵
顺序打印矩阵 思路 参考代码 #include <iostream> using namespace std; ], int row, int col) { || col < ) r ...
- 通过修改然后commit的方式创建自己的镜像
创建自己的镜像:通过现有的镜像来创建自己的镜像.1.首先拉取一个镜像到本地$ sudo docker imagesREPOSITORY TAG IMA ...
- Linux命令 ls -l s输出内容含义详解
1. ls 只显示文件名或者文件目录 2. ls -l(这个参数是字母L的小写,不是数字1) 用来查看详细的文件资料 在某个目录下键入ls -l可能会显示如下信息: 文件属性(占10个字符空间) ...
- Dynamics 365 for CRM: Sitemap站点图的可视化编辑功能
Dynamics 365 for CRM 提供了Sitemap站点图的可视化编辑功能 在之前的所有版本中,我们只能通过从系统中导出站点图的XML进行编辑后再导入(容易出错),或使用第三方的Sitema ...