Turning off Browser Window Scrollbars Programmatically with Angular | Task

Ole Ersoy
Aug - 24  -  1 min

Scenario

We are creating a layout where we only wish to have the content panel inside the layout be scrollable, and thus we wish to turn off scrolling for the viewport programmatically from within the component.

Approach

Inject the DOCUMENT and set overflow to hidden on the body.

constructor(@Inject(
    DOCUMENT) private document: Document,
    protected renderer: Renderer2
) {
    this.renderer.setStyle(document.body, 'overflow', 'hidden');
}

Demo