zoukankan      html  css  js  c++  java
  • [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.

  • 相关阅读:
    DOM的重点核心
    window的Navigator 对象
    meta标签的http-equiv与content解析
    深拷贝与浅拷贝
    web安全CSRF和XSS
    同源策略与跨域问题
    instanceof与constructor的区别
    javascript原型对象与原型链
    Dom事件
    CSS盒模型的介绍
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6471365.html
Copyright © 2011-2022 走看看