Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 1x | import {Injectable} from '@angular/core';
// Taken from https://juristr.com/blog/2016/09/ng2-get-window-ref/
// Here to make transition to Angular Universal later easier
/* This interface is optional, showing how you can add strong typings for custom globals.
// Just use "Window" as the type if you don't have custom global stuff
export interface ICustomWindow extends Window {
__custom_global_stuff: string;
} */
function getWindow(): any {
if (typeof window !== 'undefined') {
return window;
} else {
throw new Error('Cannot find window object - running in SSR?');
}
}
@Injectable({providedIn: 'root'})
export class WindowRefService {
public nativeWindow(): Window {
return getWindow();
}
}
|