Skip to content

Commit

Permalink
fix(range): prevent change detection exception
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jun 1, 2016
1 parent cffa84c commit 7e4b13d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/components/range/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {NG_VALUE_ACCESSOR} from '@angular/common';
import {Form} from '../../util/form';
import {isTrueProperty, isNumber, isString, isPresent, clamp} from '../../util/util';
import {Item} from '../item/item';
import {pointerCoord, Coordinates} from '../../util/dom';
import {pointerCoord, Coordinates, raf} from '../../util/dom';


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

this.createTicks();

// add touchstart/mousedown listeners
this._renderer.listen(this._slider.nativeElement, 'touchstart', this.pointerDown.bind(this));
this._mouseRemove = this._renderer.listen(this._slider.nativeElement, 'mousedown', this.pointerDown.bind(this));

this.createTicks();
}

/**
Expand Down Expand Up @@ -544,18 +544,18 @@ export class Range {
*/
createTicks() {
if (this._snaps) {
this._ticks = [];
for (var value = this._min; value <= this._max; value += this._step) {
var ratio = this.valueToRatio(value);
this._ticks.push({
ratio: ratio,
left: `${ratio * 100}%`,
});
}
this.updateTicks();

} else {
this._ticks = null;
raf(() => {
// TODO: Fix to not use RAF
this._ticks = [];
for (var value = this._min; value <= this._max; value += this._step) {
var ratio = this.valueToRatio(value);
this._ticks.push({
ratio: ratio,
left: `${ratio * 100}%`,
});
}
this.updateTicks();
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/range/test/basic/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component} from '@angular/core';
import {ionicBootstrap} from '../../../../../src';
import {ionicBootstrap, Range} from '../../../../../src';


@Component({
Expand All @@ -13,7 +13,7 @@ class Page1 {
dualValue: any;
dualValue2 = {lower: 33, upper: 60};

rangeChange(ev) {
rangeChange(ev: Range) {
console.log(`range, change, ratio: ${ev.ratio}, value: ${ev.value}`);
}

Expand Down

0 comments on commit 7e4b13d

Please sign in to comment.