gAngular2 setHow to not check component value change in setInterval

Asked 1 years ago, Updated 1 years ago, 84 views

I'm creating an auto-scrolling function on the screen, but it becomes very heavy because the value change check is performed in setInterval.
Auto-scrolling does not change the value of the component, so you do not need to check the change check.
Are there any setInterval functions that do not perform change checks?

javascript angularjs typescript

2022-09-30 19:43

1 Answers

You should be able to use the runOutsideAngular method in the NgZone class.Obtain an instance of NgZone in the Dependency Injection of the component before using it.

Sample

export classSomeCmp{
  constructor(privateZone:NgZone){}

  ngOnInit(){
    This.ngZone.runOutsideAngular()=>{
      setInterval (()=>{})
    });
  }
}

https://angular.io/docs/ts/latest/api/core/index/NgZone-class.html#!#runOutsideAngular-anchor


2022-09-30 19:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.