4

I would like to scroll to top on NavigationEnd.

Previously I did like this:

  this.router.events
  .pipe(filter(event => event instanceof NavigationEnd))
  .subscribe((event) => {
    // scroll to top on navigation
    window.scrollTo(0, 0)
  });

And that worked but now we have changed the html/css layout so we would like to rely on the CdkScrollable directive but I can't get the elementRef?

Mackelito
  • 4,213
  • 5
  • 39
  • 78

1 Answers1

3

In component @ViewChildren(CdkScrollable) cdkScrollable;

In function scrollToEnd this.cdkScrollable.first.scrollTo({bottom: 0});