Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions angular-countUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,9 @@
},
link: function ($scope, $el, $attrs) {

var options = {};

if ($scope.filter) {
var filterFunction = createFilterFunction();
options.formattingFn = filterFunction;
}

if ($scope.options) {
angular.extend(options, $scope.options);
$scope.options.formattingFn = filterFunction;
}

var countUp = createCountUp($scope.startVal, $scope.endVal, $scope.decimals, $scope.duration);
Expand All @@ -67,7 +61,7 @@
};
}

function createCountUp(sta, end, dec, dur) {
function createCountUp(sta, end, dec, dur, options) {
sta = sta || 0;
if (isNaN(sta)) sta = Number(sta.match(/[\d\-\.]+/g).join('')); // strip non-numerical characters
end = end || 0;
Expand Down Expand Up @@ -126,10 +120,20 @@
if (countUp !== null) {
countUp.update($scope.endVal);
} else {
countUp = createCountUp($scope.startVal, $scope.endVal, $scope.decimals, $scope.duration);
countUp = createCountUp($scope.startVal, $scope.endVal, $scope.decimals, $scope.duration, $scope.options);
animate();
}
});

$scope.$watch('options', function (newValue, oldValue) {

if (newValue === null || newValue === oldValue)
return;

// Create new instance every time.
countUp = createCountUp($scope.startVal, $scope.endVal, $scope.decimals, $scope.duration, $scope.options);
animate();
}, true); // true for deep watch because options is an object.
}
};
}]);
Expand Down