From c2029f7927dd2fa05741034b28cc6271291f3dc2 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sat, 23 Feb 2019 17:05:19 -0600 Subject: [PATCH] fix(ssr): fix window references --- src/@ionic-native/core/decorators/common.ts | 11 +++++++++-- src/@ionic-native/core/ionic-native-plugin.ts | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/@ionic-native/core/decorators/common.ts b/src/@ionic-native/core/decorators/common.ts index 30fed6e7..0c213f83 100644 --- a/src/@ionic-native/core/decorators/common.ts +++ b/src/@ionic-native/core/decorators/common.ts @@ -149,7 +149,11 @@ function wrapObservable(pluginObj: any, methodName: string, args: any[], opts: a * @returns {Observable} */ function wrapEventObservable(event: string, element: any): Observable { - element = element ? get(window, element) : window; + if (typeof window !== 'undefined') { + element = element && typeof window !== 'undefined' ? get(window, element) : window; + } else { + element = element || {}; + } return fromEvent(element, event); } @@ -307,7 +311,10 @@ export function callInstance( } export function getPlugin(pluginRef: string): any { - return get(window, pluginRef); + if (typeof window !== 'undefined') { + return get(window, pluginRef); + } + return null; } export function get(element: Element | Window, path: string) { diff --git a/src/@ionic-native/core/ionic-native-plugin.ts b/src/@ionic-native/core/ionic-native-plugin.ts index 3bde7440..e3ff2344 100644 --- a/src/@ionic-native/core/ionic-native-plugin.ts +++ b/src/@ionic-native/core/ionic-native-plugin.ts @@ -26,7 +26,10 @@ export class IonicNativePlugin { * Returns the original plugin object */ static getPlugin(): any { - return get(window, this.pluginRef); + if (typeof window !== 'undefined') { + return get(window, this.pluginRef); + } + return null; } /**