Skip to content

Instantly share code, notes, and snippets.

@MarsiBarsi
Created June 14, 2020 15:04
Show Gist options
  • Save MarsiBarsi/1fc7617bd5cbe8a1a9cdaf30d51baff3 to your computer and use it in GitHub Desktop.
Save MarsiBarsi/1fc7617bd5cbe8a1a9cdaf30d51baff3 to your computer and use it in GitHub Desktop.
window token
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