I played with this for a while and came up with several options for you. See My Plunkr to see them in action.
Option 1: no need to update the scope value when changing the slider
This will work with HTML from your question. You must change the directive code below.
app.directive('slider', function slider() { return { restrict: 'A', link: function(scope, element, attrs) { attrs.$observe('sliderValue', function(newVal, oldVal) { element.slider('setValue', newVal); }); } } });
Option 2. Bilateral binding to scope property
If you need to change the scope property when dragging the slider handle, you must change the directive to the following:
app.directive('sliderBind', ['$parse', function slider($parse) { return { restrict: 'A', link: function(scope, element, attrs) { var val = $parse(attrs.sliderBind); scope.$watch(val, function(newVal, oldVal) { element.slider('setValue', newVal); });
The markup for this changes slightly:
<div class="slider slider-default"> <input type="text" data-slider-bind="slider2" class="slider-span" value="" data-slider-orientation="vertical" data-slider-min="0" data-slider-max="200" data-slider-selection="after" data-slider-tooltip="hide" /> </div>
Note the use of the data-slider-bind attribute to specify the scope property for binding and the absence of the data-slider-value attribute.
I hope one of these two options is what you were after.
source share