Skip to content

Instantly share code, notes, and snippets.

@lokanx
Created December 10, 2015 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lokanx/cc022ee0b8999cd3b7f5 to your computer and use it in GitHub Desktop.
Save lokanx/cc022ee0b8999cd3b7f5 to your computer and use it in GitHub Desktop.
window-service.ts
import {Injectable, Provider} from 'angular2/angular2'
import {window} from 'angular2/src/facade/browser';
import {unimplemented} from 'angular2/src/facade/exceptions';
function _window(): Window {
return window
}
export abstract class WINDOW {
get nativeWindow(): Window {
return unimplemented();
}
}
class WindowRef_ extends WINDOW {
constructor() {
super();
}
get nativeWindow(): Window {
return _window();
}
}
export const WINDOW_PROVIDERS = [
new Provider(WINDOW, {useClass: WindowRef_}),
];
@lokanx
Copy link
Author

lokanx commented Dec 10, 2015

And to use it:

import {WINDOW} from './windowService';

@Injectable()
export class PersonStorageService {
    win: Window;

    constructor(win: WINDOW) {
        this.win = win.nativeWindow;
    }
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment