Last active
June 29, 2021 09:13
-
-
Save tamascsaba/fd30d91c7b3065981049d7c4d4eb8fce to your computer and use it in GitHub Desktop.
Angular scroll performance tuning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {fromEvent} from 'rxjs/observable/fromEvent'; | |
import {animationFrame} from 'rxjs/scheduler/animationFrame'; | |
export class FooComponent implements AfterViewInit { | |
.... | |
ngAfterViewInit() { | |
// Angular scroll performance tuning | |
this.zone.runOutsideAngular(() => { | |
fromEvent(window, 'scroll').subscribe(() => { | |
animationFrame.schedule(() => { | |
this.zone.run(() => { | |
this.action(); | |
}); | |
}); | |
}); | |
}); | |
} | |
action() { | |
// Do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment