Created
March 25, 2013 20:15
-
-
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.
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
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" /> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scope[attrs.rangeControl]... should be scope[attrs.rangeChange]...