fix(ssr): fix window references

This commit is contained in:
Adam Bradley 2019-02-23 17:05:19 -06:00
parent 5b1bdc37e0
commit c2029f7927
2 changed files with 13 additions and 3 deletions

View File

@ -149,7 +149,11 @@ function wrapObservable(pluginObj: any, methodName: string, args: any[], opts: a
* @returns {Observable} * @returns {Observable}
*/ */
function wrapEventObservable(event: string, element: any): Observable<any> { 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); return fromEvent(element, event);
} }
@ -307,8 +311,11 @@ export function callInstance(
} }
export function getPlugin(pluginRef: string): any { export function getPlugin(pluginRef: string): any {
if (typeof window !== 'undefined') {
return get(window, pluginRef); return get(window, pluginRef);
} }
return null;
}
export function get(element: Element | Window, path: string) { export function get(element: Element | Window, path: string) {
const paths: string[] = path.split('.'); const paths: string[] = path.split('.');

View File

@ -26,8 +26,11 @@ export class IonicNativePlugin {
* Returns the original plugin object * Returns the original plugin object
*/ */
static getPlugin(): any { static getPlugin(): any {
if (typeof window !== 'undefined') {
return get(window, this.pluginRef); return get(window, this.pluginRef);
} }
return null;
}
/** /**
* Returns the plugin's name * Returns the plugin's name