sparkalow / angular-count-to Goto Github PK
View Code? Open in Web Editor NEWAngular directive to animate counting to a number
License: MIT License
Angular directive to animate counting to a number
License: MIT License
The current version does not add commas so I added a regex to display commas.
var countTo = angular.module('countTo', [])
.directive('countTo', ['$timeout', function ($timeout) {
return {
replace: false,
scope: true,
link: function (scope, element, attrs) {
var e = element[0];
var num, refreshInterval, duration, steps, step, countTo, value, increment;
var calculate = function () {
refreshInterval = 30;
step = 0;
scope.timoutId = null;
countTo = parseInt(attrs.countTo) || 0;
scope.value = parseInt(attrs.value, 10) || 0;
duration = (parseFloat(attrs.duration) * 1000) || 0;
steps = Math.ceil(duration / refreshInterval);
increment = ((countTo - scope.value) / steps);
num = scope.value;
}
var tick = function () {
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
scope.timoutId = $timeout(function () {
num += increment;
step++;
if (step >= steps) {
$timeout.cancel(scope.timoutId);
num = countTo;
e.textContent = numberWithCommas(countTo);
} else {
var Content = Math.round(num);
tick();
e.textContent = numberWithCommas(Content);
}
}, refreshInterval);
}
var start = function () {
if (scope.timoutId) {
$timeout.cancel(scope.timoutId);
}
calculate();
tick();
}
attrs.$observe('countTo', function (val) {
if (val) {
start();
}
});
attrs.$observe('value', function (val) {
start();
});
return true;
}
}
}]);
From this code :
Inject the count-to directive in your app.
var myApp = angular.module('myApp', ['count-to']);
to this code:
Inject the countTo directive in your app.
var myApp = angular.module('myApp', ['countTo']);
Your Read-me files shows 'count-to' as dependency
But the actual dependency is "countTo" and not "count-to"
There is some issue with this directive on Firefox browser, I have tested the directive in Firfox version 31.0 and its not working, and it doesn't even showing any error messages in console.
I think its the issue with "e.innerText" wchich doesn't support in Firfox. Either that should be replaced with innerHTML (supports in all browsers) or with textContent (which won't work in IE8).
We're looking to use this in a project — thanks for building it! — but I'm not finding anything on npmjs.com for it. We could create our own NPM but it's always better when the repo authors handle it, to ensure versioning stays up to date and the numbers synced.
Is this something you guys would consider doing?
Thanks!
I am using angular4 application, do you have a support for angular 4 with cli.
The "main" entry is missing from package.json and bower.json. Thus, any injector won't be able to find the script to inject into index.html.
count-to converts any input to integers, not always desirable.
Hi, how to count from 1 to 0.00000001 ?
I believe the instructions for implementing the directives need to be changed -
"count-to" doesn't work, the right namespace is "countTo".
The counter starts working if val is true, which means that when the view loads up the counter starts running straight away. Can you please add an option to trigger the count?
ERROR in node_modules/angular-count-to/src/modules/count-to.module.d.ts:6:23 - error TS2314: Generic type 'ModuleWithProviders' requires 1 type argument(s).
6 static forRoot(): ModuleWithProviders;
~~~~~~~~~~~~~~~~~~~
node_modules/angular-count-to/src/modules/count-to.module.d.ts:10:24 - error TS2314: Generic type 'ModuleWithProviders' requires 1 type argument(s).
10 static forChild(): ModuleWithProviders;
~~~~~~~~~~~~~~~~~~~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.