Skip to content

Instantly share code, notes, and snippets.

@dsebastien
Created May 12, 2020 20:56
Show Gist options
  • Save dsebastien/53b71a7bf5473985d8c459159080da51 to your computer and use it in GitHub Desktop.
Save dsebastien/53b71a7bf5473985d8c459159080da51 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 implements AfterViewInit {
...
@ViewChild("mainContent")
private mainContentElement!: ElementRef<HTMLElement>;
...
constructor(
...
@Inject(ROUTER_SCROLL_SERVICE)
private readonly routerScrollService: RouterScrollService,
...
) { ... }
...
ngAfterViewInit() {
if (this.mainContentElement) {
this.routerScrollService.setCustomViewportToScroll(this.mainContentElement.nativeElement);
} else {
this.logger.error(
"The main content element could not be found. Was it renamed? It is required here to ensure that scrolling works as expected!",
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment