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.

[Angular] Some performance tips的更多相关文章

  1. Android 性能优化(19)*代码优化11条技巧:Performance Tips

    Performance Tips 1.In this document Avoid Creating Unnecessary Objects 避免多余的对象 Prefer Static Over Vi ...

  2. SQL Server performance tips

    Refer to: http://harriyott.com/2006/01/sql-server-performance-tips A colleague of mine has been look ...

  3. Performance tips

    HTML5 Techniques for Optimizing Mobile Performance Scrolling Performance layout-performance

  4. Json.NET Performance Tips

    原文: http://www.newtonsoft.com/json/help/html/Performance.htm To keep an application consistently fas ...

  5. [Angular] Increasing Performance by using Pipe

    For example you make a function to get rating; getRating(score: number): string { let rating: string ...

  6. 翻译--Blazing fast node.js: 10 performance tips from LinkedIn Mobile

    1.避免使用同步代码: // Good: write files asynchronously fs.writeFile('message.txt', 'Hello Node', function ( ...

  7. [Javascript]3. Improve you speed! Performance Tips

    /** Let inheritance help with memory efficiency */ function SignalFire(ID, startingLogs){ this.fireI ...

  8. 10个加速Table Views开发的Tips(转)

    本文由CocoaChina译者yake_099(博客)翻译,作者:David McGraw原文:10 Actionable Performance Tips To Speed Up Your Tabl ...

  9. 【原创】大数据基础之Hive(5)性能调优Performance Tuning

    1 compress & mr hive默认的execution engine是mr hive> set hive.execution.engine;hive.execution.eng ...

随机推荐

  1. HDU 2068 RPG的错排(错排公式 + 具体解释)

    RPG的错排 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  2. Solr 倒排索引

     正排索引(正向索引):正排表是以文档的ID为关键字,表中记录文档中每个字的位置信息,查找时扫描表中每个文档中字的信息直到找出所有包含查询关键字的文档. 正排表结构如图1所示,这种组织方法在建立索引的 ...

  3. 使用差分VHD启动Win7

    平台:windows 8.1 目的:在VHD里装个Win7 介绍:建立VHD装系统姑且不表,比较有意思的是用差分VHD备份系统这点. 差分硬盘这个概念在虚拟机里常用,类似VM中的快照,不过差分硬盘更灵 ...

  4. Ubuntu14.04中踩过的坑

    今天安装Ubuntu 14.0.4,因为需要使用python3,所以就直接配置如下:sudo rm /usr/bin/pythonsudo ln -s /usr/bin/python3.5  /usr ...

  5. Java Web学习总结(7)——HttpServletRequest对象

    一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...

  6. php字符串函数分类总结

    php字符串函数分类总结 一.总结 explode  str_split  str_word_count  strtolower 二.php字符串函数分类总结 php内置了98个字符串函数(除了基于正 ...

  7. JS实现动画的四条优化方法

    JS实现动画的四条优化方法 1)如果使用的是setTimeout实现的轮询动画,在每一次执行方法之前需要把前面的设置的定时器清除掉 2)为了防止全局变量的污染,我们把定时器的返回值赋值给当前操作元素的 ...

  8. Loadrunner--参数化知识点及参数池策略

    一.为何进行脚本参数化? 脚本在录制的时候,记录的参数都是常量值,这样,虚拟用户在执行同一个脚本,向服务器发送请求时,使用的都是同一个参数值,与实际不符.所以使用参数化技术. 二.参数化的逻辑? 对脚 ...

  9. LA 2678 – Subsequence

    看到限时3S,自己写了一个二重循环的,然后华丽的 TLE...T T 瞄了瞄书上,作者的思路果然是很好.膜拜中. 他只枚举了终点,然后用二分查找. 用到了lower_bound函数,这个lower_b ...

  10. 通过WPF中UserControl内的按钮点击关闭父窗体

    原文:通过WPF中UserControl内的按钮点击关闭父窗体 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/m0_37591671/article ...