Skip to content

added watch for decimals, if you change them the model should reload #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 13 additions & 5 deletions angular-countUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// * **Author:** Jamie Perkins
//
// Creates a counting animation for numbers
// REQUIRED attributes:
// REQUIRED attributes:
// - endVal
//
// DEPENDENCY: countUp.js
Expand All @@ -18,7 +18,7 @@

/**
* count-up attribute directive
*
*
* @param {number} startVal - (optional) The value you want to begin at, default 0
* @param {number} countUp - The value you want to arrive at
* @param {number} duration - (optional) Duration in seconds, default 2.
Expand Down Expand Up @@ -75,7 +75,7 @@
dur = Number(dur) || 2;
dec = Number(dec) || 0;

// construct countUp
// construct countUp
var countUp = new CountUp($el[0], sta, end, dec, dur, options);
if (end > 999) {
// make easing smoother for large numbers
Expand Down Expand Up @@ -118,17 +118,25 @@
});
}

$scope.$watch('endVal', function (newValue, oldValue) {
function onWatch(newValue, oldValue, forceReload){
if (newValue === null || newValue === oldValue) {
return;
}

if (countUp !== null) {
if (countUp !== null && !forceReload) {
countUp.update($scope.endVal);
} else {
countUp = createCountUp($scope.startVal, $scope.endVal, $scope.decimals, $scope.duration);
animate();
}
}

$scope.$watch('decimals', function(newValue, oldValue) {
onWatch(newValue, oldValue, true);
});

$scope.$watch('endVal', function (newValue, oldValue) {
onWatch(newValue, oldValue, false);
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-countUp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.