Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@lokanx 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
You can’t perform that action at this time.