Angular: Disable Change Detector for an entire class (service or component)

后端 未结 3 517
终归单人心
终归单人心 2021-01-24 20:07

Is there a way to completely disable Angular\'s change detector if events that normally cause the change detection to run (setTimeout, setInterval, browser events, ajax calls et

3条回答
  •  难免孤独
    2021-01-24 20:49

    You can change the detection strategy of individual components with the following:

    import { Component, ChangeDetectionStrategy } from '@angular/core';
    
    @Component({
      selector: 'ws-layout-page',
      templateUrl: './layout-page.component.html',
      styleUrls: ['./layout-page.component.css'],
      changeDetection: ChangeDetectionStrategy.OnPush
    })
    export class LayoutPageComponent {
    
    }
    

    I dont know any other method that could archieve some selective turn on/of depending of where is the information coming from

提交回复
热议问题