1- import { ElementRef , Injectable , NgZone , Optional , SkipSelf } from '@angular/core' ;
2- import { isBrowser } from '../../platform/browser ' ;
1+ import { NgModule , ElementRef , Injectable , NgZone , Optional , SkipSelf } from '@angular/core' ;
2+ import { Platform , PlatformModule } from '../../platform/index ' ;
33import { Scrollable } from './scrollable' ;
44import { Subject } from 'rxjs/Subject' ;
55import { Observable } from 'rxjs/Observable' ;
@@ -18,7 +18,7 @@ export const DEFAULT_SCROLL_TIME = 20;
1818 */
1919@Injectable ( )
2020export class ScrollDispatcher {
21- constructor ( private _ngZone : NgZone ) { }
21+ constructor ( private _ngZone : NgZone , private _platform : Platform ) { }
2222
2323 /** Subject for notifying that a registered scrollable reference element has been scrolled. */
2424 _scrolled : Subject < void > = new Subject < void > ( ) ;
@@ -63,7 +63,8 @@ export class ScrollDispatcher {
6363 * to override the default "throttle" time.
6464 */
6565 scrolled ( auditTimeInMs : number = DEFAULT_SCROLL_TIME , callback : ( ) => any ) : Subscription {
66- if ( ! isBrowser ( ) ) {
66+ // Scroll events can only happen on the browser, so do nothing if we're not on the browser.
67+ if ( ! this . _platform . isBrowser ) {
6768 return Subscription . EMPTY ;
6869 }
6970
@@ -131,14 +132,23 @@ export class ScrollDispatcher {
131132 }
132133}
133134
134- export function SCROLL_DISPATCHER_PROVIDER_FACTORY ( parentDispatcher : ScrollDispatcher ,
135- ngZone : NgZone ) {
136- return parentDispatcher || new ScrollDispatcher ( ngZone ) ;
135+ export function SCROLL_DISPATCHER_PROVIDER_FACTORY (
136+ parentDispatcher : ScrollDispatcher , ngZone : NgZone , platform : Platform ) {
137+ return parentDispatcher || new ScrollDispatcher ( ngZone , platform ) ;
137138}
138139
139140export const SCROLL_DISPATCHER_PROVIDER = {
140141 // If there is already a ScrollDispatcher available, use that. Otherwise, provide a new one.
141142 provide : ScrollDispatcher ,
142- deps : [ [ new Optional ( ) , new SkipSelf ( ) , ScrollDispatcher ] , NgZone ] ,
143+ deps : [ [ new Optional ( ) , new SkipSelf ( ) , ScrollDispatcher ] , NgZone , Platform ] ,
143144 useFactory : SCROLL_DISPATCHER_PROVIDER_FACTORY
144145} ;
146+
147+
148+ @NgModule ( {
149+ imports : [ PlatformModule ] ,
150+ exports : [ Scrollable ] ,
151+ declarations : [ Scrollable ] ,
152+ providers : [ SCROLL_DISPATCHER_PROVIDER ] ,
153+ } )
154+ export class ScrollDispatchModule { }
0 commit comments