Skip to content

Instantly share code, notes, and snippets.

@johncblandii
Created March 25, 2013 20:15
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save johncblandii/5240310 to your computer and use it in GitHub Desktop.
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
Copy link

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