GithubHelp home page GithubHelp logo

sparkalow / angular-count-to Goto Github PK

View Code? Open in Web Editor NEW
150.0 150.0 97.0 6.48 MB

Angular directive to animate counting to a number

License: MIT License

JavaScript 90.74% Shell 1.68% Ruby 3.66% Batchfile 2.01% HTML 1.91%

angular-count-to's People

Contributors

gor-julhakyan avatar michalgm avatar sparkalow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

angular-count-to's Issues

No commas, formatting display

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;
        }
    }

}]);

This need to be change

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']);

Issue with firefox

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).

Would love to have an NPM for this!

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!

No "main" entry in bower.json

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.

Trigger the counting sequence

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?

Not supported in Angular 10

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;
~~~~~~~~~~~~~~~~~~~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.