Last active
August 29, 2015 14:13
-
-
Save NoxHarmonium/d53d07bda7417d6d8004 to your computer and use it in GitHub Desktop.
Directive to bind jQuery-UI slider to Angular js and ngChange support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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