Created
May 12, 2020 20:40
-
-
Save dsebastien/960fbbdef5c2d81a9f33d3242c864804 to your computer and use it in GitHub Desktop.
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
... | |
@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