refer :

https://blog.angularindepth.com/all-you-need-to-know-about-ivy-the-new-angular-engine-9cde471f42cf

https://blog.angularindepth.com/asynchronous-modules-and-components-in-angular-ivy-1c1d79d45bd3

https://blog.angularindepth.com/the-future-of-standalone-components-in-the-post-ivy-release-days-e7ed9b9b4dcd

https://blog.nrwl.io/metaprogramming-higher-order-components-and-mixins-with-angular-ivy-75748fcbc310

https://www.softwarearchitekt.at/aktuelles/architecture-with-ivy-a-possible-future-without-angular-modules/

https://www.softwarearchitekt.at/aktuelles/architecture-with-angular-ivy-part-2-higher-order-and-dynamic-components/

https://blog.ninja-squad.com/2019/05/07/what-is-angular-ivy/

https://blog.angularindepth.com/angular-ivy-change-detection-execution-are-you-prepared-ab68d4231f2c (change detech)

https://blog.angularindepth.com/ivy-engine-in-angular-first-in-depth-look-at-compilation-runtime-and-change-detection-876751edd9fd  (change detech)

https://netbasal.com/optimizing-angular-change-detection-triggered-by-dom-events-d2a3b2e11d87 (change detech)

听说 Angular 9 没有什么了不起的功能发布,只是将某个配置修改成默认而已. 团队真不给力丫...

修改的这个配置是渲染引擎, 名叫 ivy,好像是因为第 4 代所以叫这个名字.

它有什么不一样的地方呢 ?

主要是组件编辑后的代码不同了,对树摇友好一点. 代码好看一点. size 小一点.

1. 长相.

编辑后都把代码写进静态函数了, build 模板是直接使用调用式..elementstart 会直接调用 dom api 去创建 element (好像是这样)

注意那个 ɵfac 之后会讲到.

2. no more entry component.

以前要动态出组件挺麻烦的,要 entry component 而且 module 也不可以 lazyload

现在简单很多了

  open() {
import('./abc/abc.module').then((m) => {
ɵcreateInjector(m.AbcModule, this.injector);
this.dialog.open(AbcComponent, { width: '1000px' });
}); // import('./abc/abc.component').then((m) => {
// const factory = this.cfr.resolveComponentFactory(m.AbcComponent);
// this.target.createComponent(factory, 0, this.injector);
// }); // import('./abc/abc.component').then((m) => ɵrenderComponent(m.AbcComponent,
// { injector: this.injector, host: this.el.nativeElement }
// ));
}

直接 lazy load 然后链接 injector 给这个模块,就可以用任何组件了.

模块无需 entry component 也不用 export

@NgModule({
declarations: [AbcComponent, XyzComponent],
imports: [
CommonModule
],
// exports: [AbcComponent, XyzComponent],
// entryComponents: [AbcComponent]
})
export class AbcModule { }

注意:  如果你没用 import module 而是直接 append component 你会发现也是可以跑的, 但是如果这个 component 里面有依赖其它的 component 就不行了, 除非你没用使用 module, 而是通过组件自己去写依赖.

目前官方没用给出不写 module 的方式. 相信之后会出, 可能会长的像 2.0 rc 那样,那个年代 ngmodule 还没有出来呢...

另一个重点是 injector, 我们 import 过来后, 需要用这个 module build 一个 inujector, 因为这个 module 里面可能有 provider 然后才能 append component.

3. optional ng module

ivy 后, ng module 变得是一个 optional, 当然 ng module 为我们封装了很多好料, injector, detech change, life cycle 等等.

然后你不要用它,全部都要自己弄咯. 文章里有参考,我自己没有这个需求以后有才补上 demo.

4. HOC (height order component)

目前还感受不到它能做什么大事情. 它的功能是说,现在我们可以通过 decorator 去拦截 ɵfac (这个 ɵ(Greek Theta) 是因为目前这个方法是 private 的.)

拦截后我们可以重写 ɵfac

export function HOC() {
return (cmpType) => {
const originalFactory = cmpType.ɵfac;
cmpType.ɵfac = (...args: any) => {
const cmp = originalFactory(...args);
console.log('component instance', cmp); // 重点
return cmp;
};
};
} @HOC()
@Component({
selector: 'app-test-dialog',
templateUrl: './test-dialog.component.html',
styleUrls: ['./test-dialog.component.scss']
})
export class TestDialogComponent implements OnInit {

看重点,这里我们就可以获取到组件实例,然后可以做一个封装,比如修改一些接口等等的,可以算是装修模式吧. ngOnChange 就是用这个方式去实现的哦,它已经不是内置的 life cycle hook 了.

我们也可以通过类似方式去加强 life cycle hook.

4.I18n

ng 的 i18n 非常弱, 绝大部分功能从 v5 说要做到 v9 都没有实现.

v9 后已经被分离出来了,如果要使用的话需要 install package @angular/localize

之前 angular.json 里面配置 "i18nLocale": "en-US" 的话也会直接报错, 如果没有装 package 的话。
 

Angular 学习笔记 (Angular 9 & ivy)的更多相关文章

  1. angular学习笔记-angular中怎么获取dom元素

    步骤分解: 第一步:给要获取的元素一个ng-model变量,并且绑定事件啦! <div class="home" ng-model="dirName" n ...

  2. angular学习笔记(三十一)-$location(2)

    之前已经介绍了$location服务的基本用法:angular学习笔记(三十一)-$location(1). 这篇是上一篇的进阶,介绍$location的配置,兼容各版本浏览器,等. *注意,这里介绍 ...

  3. angular学习笔记(三十一)-$location(1)

    本篇介绍angular中的$location服务的基本用法,下一篇介绍它的复杂的用法. $location服务的主要作用是用于获取当前url以及改变当前的url,并且存入历史记录. 一. 获取url的 ...

  4. angular学习笔记(三十)-指令(10)-require和controller

    本篇介绍指令的最后两个属性,require和controller 当一个指令需要和父元素指令进行通信的时候,它们就会用到这两个属性,什么意思还是要看栗子: html: <outer‐direct ...

  5. angular学习笔记(三十)-指令(7)-compile和link(2)

    继续上一篇:angular学习笔记(三十)-指令(7)-compile和link(1) 上一篇讲了compile函数的基本概念,接下来详细讲解compile和link的执行顺序. 看一段三个指令嵌套的 ...

  6. angular学习笔记(三十)-指令(7)-compile和link(1)

    这篇主要讲解指令中的compile,以及它和link的微妙的关系. link函数在之前已经讲过了,而compile函数,它和link函数是不能共存的,如果定义了compile属性又定义link属性,那 ...

  7. angular学习笔记(三十)-指令(6)-transclude()方法(又称linker()方法)-模拟ng-repeat指令

    在angular学习笔记(三十)-指令(4)-transclude文章的末尾提到了,如果在指令中需要反复使用被嵌套的那一坨,需要使用transclude()方法. 在angular学习笔记(三十)-指 ...

  8. angular学习笔记(三十)-指令(5)-link

    这篇主要介绍angular指令中的link属性: link:function(scope,iEle,iAttrs,ctrl,linker){ .... } link属性值为一个函数,这个函数有五个参数 ...

  9. angular学习笔记(三十)-指令(2)-restrice,replace,template

    本篇主要讲解指令中的 restrict属性, replace属性, template属性 这三个属性 一. restrict: 字符串.定义指令在视图中的使用方式,一共有四种使用方式: 1. 元素: ...

随机推荐

  1. 模型稳定性指标—PSI

    由于模型是以特定时期的样本所开发的,此模型是否适用于开发样本之外的族群,必须经过稳定性测试才能得知.稳定度指标(population stability index ,PSI)可衡量测试样本及模型开发 ...

  2. 多层If语句 和 表格驱动 的对比

    网文提到表格驱动,总喜欢拿一层if做例子,然而这样未免也太简单. 下文是三层缩进的if和表驱动比较,大家可自行判断优劣. 业务是这样的,某景点分旺季票价和淡季票价,淡季票为旺季的一半,15岁以下孩子再 ...

  3. 浏览器并发数 network.http.max-connections

    network.http.max-connections https://bugs.chromium.org/p/chromium/issues/detail?id=12066 https://chr ...

  4. 001 安装mysql

    在安装docker之后,安装一个mysql的容器试试手.可以参考违章: URL: https://www.cnblogs.com/limingxie/p/8655457.html

  5. Jupyter Notebook in a virtual environment (virtualenv)

    $ python -m venv projectname $ source projectname/bin/activate (venv) $ pip install ipykernel (venv) ...

  6. flutter PopupMenuButton弹出式菜单列表

    import 'package:flutter/material.dart'; class PopupMenuButtonDemo extends StatefulWidget { @override ...

  7. sqllite connectionstring setting

    https://www.connectionstrings.com/sqlite/ SQLite.NET Basic Data Source=c:\mydb.db;Version=3; Version ...

  8. S: WARNING: Could not write to (C:\Users\Administrator\AppData\Local\apktool\framework), using C:\Users\ADMINI~1\AppData\Local\Temp\ instead...

    使用ApkIDE反编译修改后,重新编译生成APK报错: > 正在编译Apk... - - 失败:S: WARNING: Could not write to (C:\Users\Administ ...

  9. ABAP DEMO so批量导入

    *&---------------------------------------------------------------------* *& Report YDEMO_015 ...

  10. JAVA协程 纤程 与Quasar 框架

    ava使用的是系统级线程,也就是说,每次调用new Thread(....).run(),都会在系统层面建立一个新的线程,然鹅新建线程的开销是很大的(每个线程默认情况下会占用1MB的内存空间,当然你愿 ...