[Angular] Some performance tips
The talk from here.
1. The lifecycle in Angular component:
constructor vs ngOnInit:
Constructor: only used for injection.
ngOnInit: for data initlization.
About ngOnInit:
I am not sure the example is good or not. Because it is not a good choice to use 'document.querySelector'.
this.elDuceDateContainer = document.querySelector('.dueDatePopover-container')
I would rather use 'ref' or '@ViewChild'. But might be it is a good adivse that avoid init too many variable in ngOnInit if not going to use right away.
You have to know that why change detection works. It handle async code and setTimeout, setTimeInterval, DOM event, mouse event... they are all async opreations.
So it will trigger change detection.
If you have to use setTimeout in your component, and you don't want change detection to detect the changes, you can use NgZone to make it run outside the change detection.
constructor(private ngZone: NgZone) {} ngAfterViewInit() {
this.ngZone.runOutsideAngular(() => this.paint());
}
Noramlly I won't use any jQuery plugin. But take this as an advise.
最新文章
- 【转】gc日志分析工具
- jquery操作radio单选按钮、checked复选框。
- 光流算法:Brox算法
- protobuf的安装和使用
- delphi 插入 HTML代码 播放器
- JavaScript面向对象精要
- Python 3
- Android ListView Adapter的getItemViewType和getViewTypeCount多种布局
- 由浅入深的讲述Get和Post的区别
- Docker环境编译时的错误记录
- 2018-2019-2 网络对抗技术 20165320 Exp2 后门原理与实践
- 配置ASM以及创建恢复目录
- 渗透中Meterpreter基本操作和对应的windows上的排查或者现象
- C#之使用AutoUpdater自动更新客户端
- Spring Cloud限流思路及解决方案
- Oracle游标解析
- angular 程序架构
- EasyMock set方法报错: java.lang.AssertionError
- bzoj 1131 简单树形dp
- ajax请求步骤