Created
June 14, 2020 15:04
-
-
Save MarsiBarsi/1fc7617bd5cbe8a1a9cdaf30d51baff3 to your computer and use it in GitHub Desktop.
window token
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
import {DOCUMENT} from '@angular/common'; | |
import {inject, InjectionToken} from '@angular/core'; | |
export const WINDOW = new InjectionToken<Window>( | |
'An abstraction over global window object', | |
{ | |
factory: () => { | |
const {defaultView} = inject(DOCUMENT); | |
if (!defaultView) { | |
throw new Error('Window is not available'); | |
} | |
return defaultView; | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment