ANGULAR CHANGE DETECTION EXPLAINED

引发脏治检查有三种方式:

  1. Events - click, submit, …
  2. XHR - Fetching data from a remote server
  3. Timers - setTimeout(), setInterval()

跳过子组件检查

跳过没必要的子组件检查可以提升性能
input是一个observables的时候, 如何实现跳过DC?

@Component({
  template: '{{counter}}',
  changeDetection: ChangeDetectionStrategy.OnPush
})
class CartBadgeCmp {

  @Input() addItemStream:Observable<any>;
  counter = 0;

  ngOnInit() {
    this.addItemStream.subscribe(() => {
      this.counter++; // application state changed
    })
  }
}
constructor(private cd: ChangeDetectorRef) {}

ngOnInit() {
    this.addItemStream.subscribe(() => {
      this.counter++; // application state changed
      this.cd.markForCheck(); // marks path
    })
  }
}

Virtual DOM

ng2引入VM, 实现只更新变化的视图部分

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2021-06-25
  • 2021-10-18
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
相关资源
相似解决方案