// import { Injectable } from '@angular/core'; // function _window(): any { // // return the global native browser window object // return window; // } // @Injectable() // export class WindowRefService { // get nativeWindow(): any { // return _window(); // } // } import { isPlatformBrowser } from '@angular/common'; import { InjectionToken, PLATFORM_ID, Injectable } from '@angular/core'; import * as i0 from "@angular/core"; /** * Create a new injection token for injecting the window into a component. */ export const WINDOW = new InjectionToken('WindowToken'); /** * Define abstract class for obtaining reference to the global window object. */ export class WindowRef { get nativeWindow() { throw new Error('Not implemented.'); } } /** * Define class that implements the abstract class and returns the native window object. */ class BrowserWindowRef extends WindowRef { constructor() { super(); } /** * @returns window object */ get nativeWindow() { return window; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BrowserWindowRef, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BrowserWindowRef }); } export { BrowserWindowRef }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BrowserWindowRef, decorators: [{ type: Injectable }], ctorParameters: function () { return []; } }); /** * Create an factory function that returns the native window object. * @param browserWindowRef Native window object * @param platformId id of platform * @returns type of platform of empty object */ export function windowFactory(browserWindowRef, platformId) { if (isPlatformBrowser(platformId)) { return browserWindowRef.nativeWindow; } const obj = { setTimeout: (func, time) => { }, clearTimeout: (a) => { } }; return obj; } /** * Create a injectable provider for the WindowRef token that uses the BrowserWindowRef class. */ export const browserWindowProvider = { provide: WindowRef, useClass: BrowserWindowRef }; /** * Create an injectable provider that uses the windowFactory function for returning the native window object. */ export const windowProvider = { provide: WINDOW, useFactory: windowFactory, deps: [WindowRef, PLATFORM_ID] }; /** * Create an array of providers. */ export const WINDOW_PROVIDERS = [browserWindowProvider, windowProvider]; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2luZG93LXJlZi5zZXJ2aWNlLmpzIiw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