Last active
July 1, 2021 22:12
-
-
Save boyney123/8931852 to your computer and use it in GitHub Desktop.
odometer.js - Angular Directive Example
This file contains hidden or 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
//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); | |
}); | |
} | |
}; | |
}); |
This file contains hidden or 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
<div angular-odometer data-odometer="value"></div> |
This file contains hidden or 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
//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