Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

Can't set initial value #95

Open
TroyWolf opened this issue Oct 4, 2015 · 6 comments
Open

Can't set initial value #95

TroyWolf opened this issue Oct 4, 2015 · 6 comments

Comments

@TroyWolf
Copy link

TroyWolf commented Oct 4, 2015

Angular binding via ng-model only works one way. If I move the slider, my scope variable is changed accordingly. The binding from the UI to the script works. However, if I change the value of the scope variable, the slider does not change.

In fact, I am unable to set an initial value per the doc in the "slider" directive. e.g. value="7". I did find that if data-slider-value="7" does work to set the initial value. It does not, however, make the Angular binding work.

@rosenfeldalon
Copy link

Same issue here, I created a Stack Overflow ticket, so if anyone has this issue as well can find a solution once presented

@vim-zz
Copy link

vim-zz commented Feb 1, 2016

+1

1 similar comment
@dwjohnston
Copy link

+1

@dwjohnston
Copy link

Best solution for this is to set the initial value in a containing object.

ie.

<slider ng-model = "sliders.slider1Value" ... /> 

$scope.sliders = {
      slider1Value: 420
 }

@ikari-pl
Copy link

ikari-pl commented Mar 2, 2016

I seem to have half of this problem.
If there is already a $scope.options = { valA: 5, valB: 10 }, and then the slider gets created, it does not see the initial value from the scope.
Though if I switch the scope containing object after the slider is visible, the slider gets updated accordingly.

@lenniebriscoe
Copy link

lenniebriscoe commented May 26, 2016

I had a dig into the code and noticed that the Slider for Bootstrap (bootstrap-slider.js) uses the attribute "value" to set its initial values. See here for examples. Then in the angular-bootstrap-slider (slider.js) which this sits on, passes in two attributes "ngModel" and "value". The initSlider() function then does some decision making and messes around with the ngModel value incorrectly I believe. I found that if I ignore the "ngModel" and just rely on the "value" attribute I could default the initial value of the slider.

<span slider range="true" 
      precision="0" 
      scale="'logarithmic'" 
      ng-model="ngModel" 
      value="ngModel" 
      min="minValue" 
      step="1000" 
      max="maxValue"
      on-stop-slide="setValue()" 
      slider-tooltip="hide">
</span>

So in my case above (from my directive containing the slider) you can see I have set the directives ngModel the both the sliders ng-model (which I don't care about anymore) and also the value (which seems to work). ng-model is required by angular-bootstrap-slider so I had to provide it but it doesn't seem to hurt setting the value to the same attribute.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants