Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A simple input[type=range] directive for AngularJS. There is an issue databinding to value changes: https://github.com/angular/angular.js/pull/2085.
var myApp = angular.module("myApp", []);
myApp.directive("rangeChange", function ($rootScope) {
var linker = function (scope, element, attrs) {
var updateScope = function () {
scope[attrs.rangeControl](element.val());
//may need to scope.$apply here
};
element.bind("change", updateScope);
updateScope(); //get the default value
};
return {
link: linker
};
});
//Usage:
/**
* <input type="range" range-change="myScopeMethodOnAController" />
*/

teisnet commented Jan 23, 2014

scope[attrs.rangeControl]... should be scope[attrs.rangeChange]...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment