all files / app/services/ window.service.ts

100% Statements 16/16
50% Branches 1/2
100% Functions 6/6
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251×         49×       1× 1× 49×     1× 1×     1× 1× 1× 1×   1×  
import { Injectable } from '@angular/core';
import { Protocol } from '../utils/types';
 
function _window(): any {
    // return the global native browser window object
    return window;
}
 
@Injectable()
export class WindowRef {
    get nativeWindow(): any {
        return _window();
    }
 
    openExternalHttpTab(path: string): void {
        this.navigateToUrl('http', path, true);
    }
 
    navigateToUrl(protocol: Protocol, path: string, newTab: boolean) {
        let params = [`${protocol}://${path}`], window = this.nativeWindow;
        Eif (newTab) params.push('_blank');
        window.open.apply(window, params);
    }
}