You must do the binding in the directive. Look at this:
angular.module('ng', []). directive('sliderRange', function($parse, $timeout){ return { restrict: 'A', replace: true, transclude: false, compile: function(element, attrs) { var html = '<div class="slider-range"></div>'; var slider = $(html); element.replaceWith(slider); var getterLeft = $parse(attrs.ngModelLeft), setterLeft = getterLeft.assign; var getterRight = $parse(attrs.ngModelRight), setterRight = getterRight.assign; return function (scope, slider, attrs, controller) { var vsLeft = getterLeft(scope), vsRight = getterRight(scope), f = vsLeft || 0, t = vsRight || 10; var processChange = function() { var vs = slider.slider("values"), f = vs[0], t = vs[1]; setterLeft(scope, f); setterRight(scope, t); } slider.slider({ range: true, min: 0, max: 10, step: 1, change: function() { setTimeout(function () { scope.$apply(processChange); }, 1) } }).slider("values", [f, t]); }; } }; });
This shows an example of a range of sliders made using jQuery UI. Usage example:
<div slider-range ng-model-left="question.properties.range_from" ng-model-right="question.properties.range_to"></div>
Barth Zalewski Mar 27 '14 at 11:09 2014-03-27 11:09
source share