Usr
Usr

Reputation: 2838

Angular 8 Scroll to top not working with agm-map

When I change route and go to a page where there's the agm-map I can't scroll the window to top.
I've tried using

<router-outlet (activate)="onActivate($event)"></router-outlet>

and then in onActivate:

  onActivate(event) {
    window.scroll(0, 0);
  }

I've also tried

  ngAfterViewInit(){
    window.scrollTo(0, 0);
  }

and

this.router.events.subscribe((evt) => {
  if (!(evt instanceof NavigationEnd)) {
    return;
  }
  window.scrollTo(0, 0);
});

inside ngOnInit but it doesn't work: I always land on the map when navigating to the page, and not at the top.

Upvotes: 0

Views: 160

Answers (1)

Adson Rocha
Adson Rocha

Reputation: 51

Remove any height style applied to body

Upvotes: 0

Related Questions