Skip to content

Instantly share code, notes, and snippets.

@JoeyGo23
Created May 16, 2014 03:39
Show Gist options
  • Save JoeyGo23/49146d7ef48821190dc5 to your computer and use it in GitHub Desktop.
Save JoeyGo23/49146d7ef48821190dc5 to your computer and use it in GitHub Desktop.

Odometer.js init not going to work on templates of angular's ui-router, because they loaded after the scan. This directive solves the problem.

'use strict'
app = angular.module 'app', ['app.directives']
app.config ->
window.odometerOptions = {auto: false}
app.controller 'MainCtrl', ($scope) ->
$scope.myModel = 12345
###
Should be used as <odometer ng-model="myModel"></odometer>
###
'use strict'
app = angular.module 'app.directives', []
app.directive 'odometer', ->
restrict: 'E'
require: 'ngModel'
scope:
model: '=ngModel'
link: ($scope, el, attr) ->
o = new Odometer
el: el[0]
value: $scope.model
format: ''
duration: 300
$scope.$watch "model", (newVal) ->
o.update newVal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment