import { Inject, Injectable, } from '@angular/core'; import { DOCUMENT, } from '@angular/common'; @Injectable() export class DisableScrollingService { constructor( @Inject(DOCUMENT) private _document: Document, ) {} public enableScrolling() { this._setBodyOverflow(''); } public disableScrolling() { this._setBodyOverflow('hidden'); } private _setBodyOverflow(newValue: string) { const documentChildren = this._document.children; if (Array.isArray(documentChildren)) { documentChildren[0].style.overflowY = newValue; } this._document.body.style.overflowY = newValue; } }