Skip to content

Instantly share code, notes, and snippets.

@NoxHarmonium
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoxHarmonium/d53d07bda7417d6d8004 to your computer and use it in GitHub Desktop.
Save NoxHarmonium/d53d07bda7417d6d8004 to your computer and use it in GitHub Desktop.
Directive to bind jQuery-UI slider to Angular js and ngChange support
// Modified from http://stackoverflow.com/a/25585402/1153203
// to support ngModel attributes that are getterSetter functions
// see "Binding to a getter/setter" in
// https://docs.angularjs.org/api/ng/directive/ngModel
(function (module, require) {
'use strict';
var Utils = require('../../shared/utils.js');
module.exports = ['$parse', '$timeout', function($parse, $timeout) {
return {
restrict: 'AE',
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
var slider = element.slider({
value: ngModel.$viewValue,
min: parseFloat($parse(attrs.min)(scope)),
max: parseFloat($parse(attrs.max)(scope)),
step: parseFloat($parse(attrs.step)(scope)),
slide: function(event, ui) {
scope.$apply(function() {
ngModel.$setViewValue(ui.value);
});
}
});
ngModel.$render = function () {
var newValue = ngModel.$viewValue;
element.slider('value', newValue);
};
}
};
}];
})(module, require);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment