angularjs-slider icon indicating copy to clipboard operation
angularjs-slider copied to clipboard

only update model onEnd.

Open nissaw opened this issue 9 years ago • 12 comments

Steps to reproduce

  1. drag slider around and it lags on a page with many other watchers
  2. call to $apply on each change event
  3. possible to update model only onEnd event?

Expected @behaviour

Tell us what should happen Slider handle should keep up with dragging

Actual behaviour

Tell us what happens instead slider Handle lags behind #cursor

nissaw avatar Oct 06 '16 22:10 nissaw

...or something similar to debounce

nissaw avatar Oct 06 '16 23:10 nissaw

Could you please share you slider options?

ValentinH avatar Oct 07 '16 05:10 ValentinH

$scope.scoreSlider = {
  options: {
    floor: 0,
    ceil: 99,
    hideLimitLabels: true,
    showTicks: 30,
    getLegend: function (value) {
      var ticks = [0, 30, 60, 90];
      if (ticks.includes(value)) {
        return '> ' + value;
      } else {
        return null;
      }
    }
  }
};

nissaw avatar Oct 07 '16 15:10 nissaw

Do you have watchers on the score value?

ValentinH avatar Oct 07 '16 16:10 ValentinH

One {{:scoreThreshold}} in another div shown when the slider is hidden

nissaw avatar Oct 07 '16 16:10 nissaw

Have you try commenting the $scope.$apply in the library to see if it was really the reason of the slowdown?

ValentinH avatar Oct 07 '16 16:10 ValentinH

added a ng-show fn call (for debugging purposes) to the rz-slider directive and it was getting called 30+ times on a slide

nissaw avatar Oct 07 '16 17:10 nissaw

We could add an option to call applyModel on onEnd only. Would you like to submit a PR for this?

ValentinH avatar Oct 10 '16 07:10 ValentinH

Has anybody figured out a workaround for this yet? My slider values are being used to filter an ng-repeat and the filter ie being called for every single tick the slider makes while sliding.

Battleaxe19 avatar Jan 11 '17 23:01 Battleaxe19

Unfortunately the option is not available yet. I don't know if I'll add it one day... If you want you can provide a PR for it if you really need it. ;)

ValentinH avatar Jan 11 '17 23:01 ValentinH

@Battleaxe19 It is not the most elegant solution but you can do something like this:

    constructor($scope) {
        const updateValue = debounce(value => {
            $scope.$apply(() => this.debouncedValue = value);
        }, 100);

        this.debouncedValue = 100;
        this.value = 100;
        this.options = {
            floor: 1,
            ceil: 100,
            showSelectionBar: true,
            translate(value, sliderId, label) {
                if (label === 'model') {
                    return '<strong>max. ' + value + ' €</strong>';
                }

                return value + ' €';
            },
            onChange(sliderId, modelValue) {
                updateValue(modelValue);
            }
        };
    }

@ValentinH Thanks for the awesome slider btw :)

marc1404 avatar Jan 16 '17 16:01 marc1404

I'm not sure why you'd use onChange if the behavior you want is the one provided by onEnd.

bendem avatar Apr 13 '17 13:04 bendem