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 ' ;
3
3
import { Scrollable } from './scrollable' ;
4
4
import { Subject } from 'rxjs/Subject' ;
5
5
import { Observable } from 'rxjs/Observable' ;
@@ -18,7 +18,7 @@ export const DEFAULT_SCROLL_TIME = 20;
18
18
*/
19
19
@Injectable ( )
20
20
export class ScrollDispatcher {
21
- constructor ( private _ngZone : NgZone ) { }
21
+ constructor ( private _ngZone : NgZone , private _platform : Platform ) { }
22
22
23
23
/** Subject for notifying that a registered scrollable reference element has been scrolled. */
24
24
_scrolled : Subject < void > = new Subject < void > ( ) ;
@@ -63,7 +63,8 @@ export class ScrollDispatcher {
63
63
* to override the default "throttle" time.
64
64
*/
65
65
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 ) {
67
68
return Subscription . EMPTY ;
68
69
}
69
70
@@ -131,14 +132,23 @@ export class ScrollDispatcher {
131
132
}
132
133
}
133
134
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 ) ;
137
138
}
138
139
139
140
export const SCROLL_DISPATCHER_PROVIDER = {
140
141
// If there is already a ScrollDispatcher available, use that. Otherwise, provide a new one.
141
142
provide : ScrollDispatcher ,
142
- deps : [ [ new Optional ( ) , new SkipSelf ( ) , ScrollDispatcher ] , NgZone ] ,
143
+ deps : [ [ new Optional ( ) , new SkipSelf ( ) , ScrollDispatcher ] , NgZone , Platform ] ,
143
144
useFactory : SCROLL_DISPATCHER_PROVIDER_FACTORY
144
145
} ;
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