Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nate-getch/a1a7914a080658898ed29ab177837e43 to your computer and use it in GitHub Desktop.
Save nate-getch/a1a7914a080658898ed29ab177837e43 to your computer and use it in GitHub Desktop.
Using window object in Angular 2
// interface for Window
interface Window {
// add some stuff here
}
let someMockWindowObject = {
// add some mock functionality here
};
// for browser providers
provide(Window, { useValue: window });
// for node and testing
provide(Window, { useValue: someMockWindowObject })
// inject it
class Foo {
constructor(private window: Window) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment