how to disable angular2 change detection for 3rd party libraries

后端 未结 2 960
感动是毒
感动是毒 2020-12-09 05:01

I have google maps which triggers 100+ times per second change detection. how to disable change detection for this.

Click here for map preview

it will be eve

2条回答
  •  旧巷少年郎
    2020-12-09 05:31

    Another option to temporary disable change detection ChangeDetectorRef

    enabled = true;  
    constructor(private ref: ChangeDetectorRef)
    
    toggleChangeDetection() {
      if (this.enabled) 
      {
        this.enabled = false;
        this.ref.detach();
      }
      else {
        this.enabled = true;
        this.ref.reattach();
    }
    

提交回复
热议问题