Skip to content

Instantly share code, notes, and snippets.

@dsebastien
Created May 12, 2020 20:40
Show Gist options
  • Save dsebastien/960fbbdef5c2d81a9f33d3242c864804 to your computer and use it in GitHub Desktop.
Save dsebastien/960fbbdef5c2d81a9f33d3242c864804 to your computer and use it in GitHub Desktop.
...
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
@ViewChild("mainContent")
private mainContentDiv!: ElementRef<HTMLElement>;
constructor(private readonly router: Router,) {}
/**
Whenever a new route is activated
@param _event
*/
onActivate(_event: any): void {
// Scrolling back to the top
// Reference: https://stackoverflow.com/questions/48048299/angular-5-scroll-to-top-on-every-route-click/48048822
if (this.mainContentDiv) {
(this.mainContentDiv.nativeElement as HTMLElement).scrollTop = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment