Skip to content

Instantly share code, notes, and snippets.

@tamascsaba
Last active June 29, 2021 09:13
Show Gist options
  • Save tamascsaba/fd30d91c7b3065981049d7c4d4eb8fce to your computer and use it in GitHub Desktop.
Save tamascsaba/fd30d91c7b3065981049d7c4d4eb8fce to your computer and use it in GitHub Desktop.
Angular scroll performance tuning
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