@@ -39,9 +39,7 @@ import {
39
39
} from '@angular/core' ;
40
40
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
41
41
import {
42
- CanColorCtor ,
43
42
CanDisableRipple ,
44
- CanDisableRippleCtor ,
45
43
MatRipple ,
46
44
MAT_RIPPLE_GLOBAL_OPTIONS ,
47
45
mixinColor ,
@@ -132,30 +130,27 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
132
130
this . _ripple . radius = 24 ;
133
131
this . _sliderInput = this . _slider . _getInput ( this . thumbPosition ) ;
134
132
135
- this . _sliderInput . dragStart . subscribe ( ( e : MatSliderDragEvent ) => this . _onDragStart ( e ) ) ;
136
- this . _sliderInput . dragEnd . subscribe ( ( e : MatSliderDragEvent ) => this . _onDragEnd ( e ) ) ;
133
+ // Note that we don't unsubscribe from these, because they're complete on destroy.
134
+ this . _sliderInput . dragStart . subscribe ( event => this . _onDragStart ( event ) ) ;
135
+ this . _sliderInput . dragEnd . subscribe ( event => this . _onDragEnd ( event ) ) ;
137
136
138
137
this . _sliderInput . _focus . subscribe ( ( ) => this . _onFocus ( ) ) ;
139
138
this . _sliderInput . _blur . subscribe ( ( ) => this . _onBlur ( ) ) ;
140
139
141
140
// These two listeners don't update any data bindings so we bind them
142
- // outside of the NgZone to pervent angular from needlessly running change detection.
141
+ // outside of the NgZone to prevent Angular from needlessly running change detection.
143
142
this . _ngZone . runOutsideAngular ( ( ) => {
144
- this . _elementRef . nativeElement . addEventListener ( 'mouseenter' , this . _onMouseEnter . bind ( this ) ) ;
145
- this . _elementRef . nativeElement . addEventListener ( 'mouseleave' , this . _onMouseLeave . bind ( this ) ) ;
143
+ this . _elementRef . nativeElement . addEventListener ( 'mouseenter' , this . _onMouseEnter ) ;
144
+ this . _elementRef . nativeElement . addEventListener ( 'mouseleave' , this . _onMouseLeave ) ;
146
145
} ) ;
147
146
}
148
147
149
148
ngOnDestroy ( ) {
150
- this . _sliderInput . dragStart . unsubscribe ( ) ;
151
- this . _sliderInput . dragEnd . unsubscribe ( ) ;
152
- this . _sliderInput . _focus . unsubscribe ( ) ;
153
- this . _sliderInput . _blur . unsubscribe ( ) ;
154
149
this . _elementRef . nativeElement . removeEventListener ( 'mouseenter' , this . _onMouseEnter ) ;
155
150
this . _elementRef . nativeElement . removeEventListener ( 'mouseleave' , this . _onMouseLeave ) ;
156
151
}
157
152
158
- private _onMouseEnter ( ) : void {
153
+ private _onMouseEnter = ( ) : void => {
159
154
this . _isHovered = true ;
160
155
// We don't want to show the hover ripple on top of the focus ripple.
161
156
// This can happen if the user tabs to a thumb and then the user moves their cursor over it.
@@ -164,7 +159,7 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
164
159
}
165
160
}
166
161
167
- private _onMouseLeave ( ) : void {
162
+ private _onMouseLeave = ( ) : void => {
168
163
this . _isHovered = false ;
169
164
this . _hoverRippleRef ?. fadeOut ( ) ;
170
165
}
@@ -279,7 +274,7 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
279
274
multi : true
280
275
} ] ,
281
276
} )
282
- export class MatSliderThumb implements AfterViewInit , ControlValueAccessor , OnInit {
277
+ export class MatSliderThumb implements AfterViewInit , ControlValueAccessor , OnInit , OnDestroy {
283
278
284
279
// ** IMPORTANT NOTE **
285
280
//
@@ -315,7 +310,7 @@ export class MatSliderThumb implements AfterViewInit, ControlValueAccessor, OnIn
315
310
* to facilitate the two-way binding for the `value` input.
316
311
* @docs -private
317
312
*/
318
- @Output ( ) readonly valueChange : EventEmitter < number > = new EventEmitter < number > ( ) ;
313
+ @Output ( ) readonly valueChange : EventEmitter < number > = new EventEmitter < number > ( ) ;
319
314
320
315
/** Event emitted when the slider thumb starts being dragged. */
321
316
@Output ( ) readonly dragStart : EventEmitter < MatSliderDragEvent >
@@ -386,6 +381,14 @@ export class MatSliderThumb implements AfterViewInit, ControlValueAccessor, OnIn
386
381
}
387
382
}
388
383
384
+ ngOnDestroy ( ) {
385
+ this . dragStart . complete ( ) ;
386
+ this . dragEnd . complete ( ) ;
387
+ this . _focus . complete ( ) ;
388
+ this . _blur . complete ( ) ;
389
+ this . valueChange . complete ( ) ;
390
+ }
391
+
389
392
_onBlur ( ) : void {
390
393
this . _onTouched ( ) ;
391
394
this . _blur . emit ( ) ;
@@ -512,15 +515,9 @@ export class MatSliderThumb implements AfterViewInit, ControlValueAccessor, OnIn
512
515
}
513
516
514
517
// Boilerplate for applying mixins to MatSlider.
515
- /** @docs -private */
516
- class MatSliderBase {
518
+ const _MatSliderMixinBase = mixinColor ( mixinDisableRipple ( class {
517
519
constructor ( public _elementRef : ElementRef < HTMLElement > ) { }
518
- }
519
- const _MatSliderMixinBase :
520
- CanColorCtor &
521
- CanDisableRippleCtor &
522
- typeof MatSliderBase =
523
- mixinColor ( mixinDisableRipple ( MatSliderBase ) , 'primary' ) ;
520
+ } ) , 'primary' ) ;
524
521
525
522
/**
526
523
* Allows users to select from a range of values by moving the slider thumb. It is similar in
0 commit comments