Search code examples
javascriptangularjsuisliderjquery-ui-slider

Angular ui-slider - dynamic min/max values


I'm using the angular ui-slider, and I need to load the slider's min- and max values from an external source so that I can set them like this:

$scope.minMaxValues = {
      slider1: {
        min: 0,
        max: 200
      },
      slider2: {
        min: 0,
        max: 200
      },
      slider3: {
        min: 0,
        max: 200
      },
      slider4: {
        min: 0,
        max: 200
      },
      slider5: {
        min: 0,
        max: 200
      }
    };

My HTML-looks like this:

<div class = "ui-slider-range ui-slider-handle" ui-slider="{range: true}" min="minMaxValues.slider1.min" max="minMaxValues.slider1.max" step="0.01" use-decimals ng-model="sliderValues[0]"></div>

Any suggestions on how to do this would be appreciated.


Solution

  • since ui-slider uses attributes on that directive, you need pass actual values:

    <div class = "ui-slider-range ui-slider-handle" ui-slider="{range: true}" min="{{minMaxValues.slider1.min}}" max="{{minMaxValues.slider1.max}}" step="0.01" use-decimals ng-model="sliderValues[0]"></div>