Skip to content

Commit 7e4b13d

Browse files
committed
fix(range): prevent change detection exception
1 parent cffa84c commit 7e4b13d

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/components/range/range.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {NG_VALUE_ACCESSOR} from '@angular/common';
44
import {Form} from '../../util/form';
55
import {isTrueProperty, isNumber, isString, isPresent, clamp} from '../../util/util';
66
import {Item} from '../item/item';
7-
import {pointerCoord, Coordinates} from '../../util/dom';
7+
import {pointerCoord, Coordinates, raf} from '../../util/dom';
88

99

1010
const RANGE_VALUE_ACCESSOR = new Provider(
@@ -343,11 +343,11 @@ export class Range {
343343
this._renderer.setElementStyle(this._bar.nativeElement, 'left', barL);
344344
this._renderer.setElementStyle(this._bar.nativeElement, 'right', barR);
345345

346-
this.createTicks();
347-
348346
// add touchstart/mousedown listeners
349347
this._renderer.listen(this._slider.nativeElement, 'touchstart', this.pointerDown.bind(this));
350348
this._mouseRemove = this._renderer.listen(this._slider.nativeElement, 'mousedown', this.pointerDown.bind(this));
349+
350+
this.createTicks();
351351
}
352352

353353
/**
@@ -544,18 +544,18 @@ export class Range {
544544
*/
545545
createTicks() {
546546
if (this._snaps) {
547-
this._ticks = [];
548-
for (var value = this._min; value <= this._max; value += this._step) {
549-
var ratio = this.valueToRatio(value);
550-
this._ticks.push({
551-
ratio: ratio,
552-
left: `${ratio * 100}%`,
553-
});
554-
}
555-
this.updateTicks();
556-
557-
} else {
558-
this._ticks = null;
547+
raf(() => {
548+
// TODO: Fix to not use RAF
549+
this._ticks = [];
550+
for (var value = this._min; value <= this._max; value += this._step) {
551+
var ratio = this.valueToRatio(value);
552+
this._ticks.push({
553+
ratio: ratio,
554+
left: `${ratio * 100}%`,
555+
});
556+
}
557+
this.updateTicks();
558+
});
559559
}
560560
}
561561

src/components/range/test/basic/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {ionicBootstrap} from '../../../../../src';
2+
import {ionicBootstrap, Range} from '../../../../../src';
33

44

55
@Component({
@@ -13,7 +13,7 @@ class Page1 {
1313
dualValue: any;
1414
dualValue2 = {lower: 33, upper: 60};
1515

16-
rangeChange(ev) {
16+
rangeChange(ev: Range) {
1717
console.log(`range, change, ratio: ${ev.ratio}, value: ${ev.value}`);
1818
}
1919

0 commit comments

Comments
 (0)