@@ -16,7 +16,9 @@ import {
16
16
Optional ,
17
17
Output ,
18
18
Renderer2 ,
19
- ViewEncapsulation
19
+ ViewEncapsulation ,
20
+ ChangeDetectionStrategy ,
21
+ ChangeDetectorRef ,
20
22
} from '@angular/core' ;
21
23
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
22
24
import { coerceBooleanProperty , coerceNumberProperty , HammerInput } from '../core' ;
@@ -118,31 +120,32 @@ export const _MdSliderMixinBase = mixinDisabled(MdSliderBase);
118
120
styleUrls : [ 'slider.css' ] ,
119
121
inputs : [ 'disabled' ] ,
120
122
encapsulation : ViewEncapsulation . None ,
123
+ changeDetection : ChangeDetectionStrategy . OnPush ,
121
124
} )
122
125
export class MdSlider extends _MdSliderMixinBase
123
126
implements ControlValueAccessor , OnDestroy , CanDisable {
124
127
/** Whether the slider is inverted. */
125
128
@Input ( )
126
129
get invert ( ) { return this . _invert ; }
127
- set invert ( value : any ) { this . _invert = coerceBooleanProperty ( value ) ; }
130
+ set invert ( value : any ) {
131
+ this . _invert = coerceBooleanProperty ( value ) ;
132
+ this . _changeDetectorRef . markForCheck ( ) ;
133
+ }
128
134
private _invert = false ;
129
135
130
136
/** The maximum value that the slider can have. */
131
137
@Input ( )
132
- get max ( ) {
133
- return this . _max ;
134
- }
138
+ get max ( ) { return this . _max ; }
135
139
set max ( v : number ) {
136
140
this . _max = coerceNumberProperty ( v , this . _max ) ;
137
141
this . _percent = this . _calculatePercentage ( this . _value ) ;
142
+ this . _changeDetectorRef . markForCheck ( ) ;
138
143
}
139
144
private _max : number = 100 ;
140
145
141
146
/** The minimum value that the slider can have. */
142
147
@Input ( )
143
- get min ( ) {
144
- return this . _min ;
145
- }
148
+ get min ( ) { return this . _min ; }
146
149
set min ( v : number ) {
147
150
this . _min = coerceNumberProperty ( v , this . _min ) ;
148
151
@@ -151,6 +154,7 @@ export class MdSlider extends _MdSliderMixinBase
151
154
this . value = this . _min ;
152
155
}
153
156
this . _percent = this . _calculatePercentage ( this . _value ) ;
157
+ this . _changeDetectorRef . markForCheck ( ) ;
154
158
}
155
159
private _min : number = 0 ;
156
160
@@ -163,6 +167,8 @@ export class MdSlider extends _MdSliderMixinBase
163
167
if ( this . _step % 1 !== 0 ) {
164
168
this . _roundLabelTo = this . _step . toString ( ) . split ( '.' ) . pop ( ) ! . length ;
165
169
}
170
+
171
+ this . _changeDetectorRef . markForCheck ( ) ;
166
172
}
167
173
private _step : number = 1 ;
168
174
@@ -191,6 +197,8 @@ export class MdSlider extends _MdSliderMixinBase
191
197
} else {
192
198
this . _tickInterval = 0 ;
193
199
}
200
+
201
+ this . _changeDetectorRef . markForCheck ( ) ;
194
202
}
195
203
private _tickInterval : 'auto' | number = 0 ;
196
204
@@ -209,15 +217,21 @@ export class MdSlider extends _MdSliderMixinBase
209
217
return this . _value ;
210
218
}
211
219
set value ( v : number | null ) {
212
- this . _value = coerceNumberProperty ( v , this . _value || 0 ) ;
213
- this . _percent = this . _calculatePercentage ( this . _value ) ;
220
+ if ( v !== this . _value ) {
221
+ this . _value = coerceNumberProperty ( v , this . _value || 0 ) ;
222
+ this . _percent = this . _calculatePercentage ( this . _value ) ;
223
+ this . _changeDetectorRef . markForCheck ( ) ;
224
+ }
214
225
}
215
226
private _value : number | null = null ;
216
227
217
228
/** Whether the slider is vertical. */
218
229
@Input ( )
219
230
get vertical ( ) { return this . _vertical ; }
220
- set vertical ( value : any ) { this . _vertical = coerceBooleanProperty ( value ) ; }
231
+ set vertical ( value : any ) {
232
+ this . _vertical = coerceBooleanProperty ( value ) ;
233
+ this . _changeDetectorRef . markForCheck ( ) ;
234
+ }
221
235
private _vertical = false ;
222
236
223
237
@Input ( ) color : 'primary' | 'accent' | 'warn' = 'accent' ;
@@ -392,9 +406,11 @@ export class MdSlider extends _MdSliderMixinBase
392
406
393
407
constructor ( renderer : Renderer2 , private _elementRef : ElementRef ,
394
408
private _focusOriginMonitor : FocusOriginMonitor ,
409
+ private _changeDetectorRef : ChangeDetectorRef ,
395
410
@Optional ( ) private _dir : Directionality ) {
396
411
super ( ) ;
397
- this . _focusOriginMonitor . monitor ( this . _elementRef . nativeElement , renderer , true )
412
+ this . _focusOriginMonitor
413
+ . monitor ( this . _elementRef . nativeElement , renderer , true )
398
414
. subscribe ( ( origin : FocusOrigin ) => this . _isActive = ! ! origin && origin !== 'keyboard' ) ;
399
415
this . _renderer = new SliderRenderer ( this . _elementRef ) ;
400
416
}
0 commit comments