diff --git a/modules/core/src/documentinterruptsource.ts b/modules/core/src/documentinterruptsource.ts index 9b575d8..5244240 100644 --- a/modules/core/src/documentinterruptsource.ts +++ b/modules/core/src/documentinterruptsource.ts @@ -1,11 +1,13 @@ +import { Inject, PLATFORM_ID } from '@angular/core'; +import { isPlatformBrowser } from '@angular/common'; import { EventTargetInterruptOptions, EventTargetInterruptSource } from './eventtargetinterruptsource'; /* * An interrupt source that uses events on the document element (html tag). */ export class DocumentInterruptSource extends EventTargetInterruptSource { - constructor(events: string, options?: number | EventTargetInterruptOptions) { - super(document.documentElement, events, options); + constructor(events: string, options?: number | EventTargetInterruptOptions, @Inject(PLATFORM_ID) private platformId?: any) { + super(isPlatformBrowser(platformId) ? document.documentElement : null, events, options); } /* diff --git a/modules/core/src/eventtargetinterruptsource.ts b/modules/core/src/eventtargetinterruptsource.ts index 072713a..2dbcd90 100644 --- a/modules/core/src/eventtargetinterruptsource.ts +++ b/modules/core/src/eventtargetinterruptsource.ts @@ -53,6 +53,9 @@ export class EventTargetInterruptSource extends InterruptSource { this.passive = !!options.passive; const opts = this.passive ? { passive: true } : null; + if(target == null) { + return; + } const fromEvents = events.split(' ').map(eventName => Observable.fromEvent(target, eventName, opts)); this.eventSrc = Observable.merge(...fromEvents); this.eventSrc = this.eventSrc.filter(innerArgs => !this.filterEvent(innerArgs)); diff --git a/modules/core/src/windowinterruptsource.ts b/modules/core/src/windowinterruptsource.ts index c82f808..f53eb1c 100644 --- a/modules/core/src/windowinterruptsource.ts +++ b/modules/core/src/windowinterruptsource.ts @@ -1,10 +1,12 @@ +import { Inject, PLATFORM_ID } from '@angular/core'; +import { isPlatformBrowser } from '@angular/common'; import {EventTargetInterruptOptions, EventTargetInterruptSource} from './eventtargetinterruptsource'; /* * An interrupt source on the Window object. */ export class WindowInterruptSource extends EventTargetInterruptSource { - constructor(events: string, options?: number | EventTargetInterruptOptions) { - super(window, events, options); + constructor(events: string, options?: number | EventTargetInterruptOptions, @Inject(PLATFORM_ID) private platformId?: any) { + super(isPlatformBrowser(platformId) ? window : null, events, options); } }