Skip to content

Commit

Permalink
fix(ssr): fix window references
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 23, 2019
1 parent 5b1bdc3 commit c2029f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/@ionic-native/core/decorators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ function wrapObservable(pluginObj: any, methodName: string, args: any[], opts: a
* @returns {Observable}
*/
function wrapEventObservable(event: string, element: any): Observable<any> {
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);
}

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/@ionic-native/core/ionic-native-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit c2029f7

Please sign in to comment.