Skip to content

Instantly share code, notes, and snippets.

@boyney123
Last active July 1, 2021 22:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boyney123/8931852 to your computer and use it in GitHub Desktop.
Save boyney123/8931852 to your computer and use it in GitHub Desktop.
odometer.js - Angular Directive Example
//Directive
angularApp.directive('angularOdometer', function () {
return {
restrict: 'A',
link: function(scope, element, attrs) {
//Creates new instance of odometer for the element
new Odometer({el: element[0], value: scope[attrs.odometer]});
//Watch for changes and update the element value (causing odometer to redraw)
scope.$watch(attrs.odometer, function(val) {
element.text(val);
});
}
};
});
<div angular-odometer data-odometer="value"></div>
//Example controller that binds to the view
angularApp.controller('OdometerCtrl.js', function ($scope) {
$scope.value = 2000;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment