tb / ng2-nouislider

Angular2 noUiSlider directive
http://tb.github.io/ng2-nouislider/
MIT License
184 stars 114 forks source link

change event is continuously triggered while dragging #169

Open khaledjendi opened 6 years ago

khaledjendi commented 6 years ago

Hi,

I did same implementation as in the demo for the range slider. The problem is the change event is keep triggered continuously while dragging. How can I keep it triggered only once after I finish dragging the slider bullet?

I am using angular 5.2.0 I included a snapshot for the console of change event below.

image

Amarnath510 commented 6 years ago

@jSchnitzer1 Were you able to solve this issue? It's been 5 days and no one replied so thought of asking. I currently have the same problem and was looking out for a solution.

Below is my implementation, the slider just emits before the drag is completed and I think I need to fix it in rangeChanged method but was not sure how to solve this.

<nouislider [connect]="true"
            [min]="minimum"
            [max]="maximum"
            [config]="{margin:step}" 
            [keyboard]="true"
            [step]="step"
            [(ngModel)]="range"
            (ngModelChange)="rangeChanged($event)">
</nouislider>
rangeChanged(updatedRange): void {
    console.info(updatedRange);
}
lgoudriaan commented 6 years ago

I have the same error, haven't found a workaround yet

JaimicoVII commented 6 years ago

A workaround i found is this:

<div>
   <nouislider [(ngModel)]="someRange"></nouislider>
</div>

Of course the value of the property someRange is updated on every ngModelChange (while your dragging), but with this workaround you can have an event when drag is over (when mouse button is released)

Hope it helps @lgoudriaan, @Amarnath510, @jSchnitzer1

lgoudriaan commented 6 years ago

@JaimicoVII thanks for the quick answer. It works but it isn't perfect. If you drag of the wrapper element it wont work.

MrWouter commented 6 years ago

The way I see it, it is expected behavior to update when the slider slides. It might not be the best case scenario for all applications (especially when doing API calls based on changed slider value).

You could do something like:

<nouislider [ngModel]="someRange" (end)="updateSomeRangeAndOtherStuff($event)"></nouislider>

lgoudriaan commented 6 years ago

@MrWouter Thanks, I didn't know about the (end) callback

inorganik commented 5 years ago

You could debounce it like this:

rangeChanged(range) {
  clearTimeout(this.dragTimeout);
  this.dragTimeout = setTimeout(() => handleStopDrag(range), 200);
}

handleStopDrag(range) {
  // gets called on stop drag
}
DanielBorel commented 5 years ago

I have similar issue. When dragging slider, i want to call other service function by some seconds. help me~

JoinThisBand commented 4 years ago

The (end) callback doesn't work if the user interacts with the slider track, rather than dragging the handle. (change) only fires once the slider change event is complete and works with the track and the handle:

(change)="doSomething($event)"