1

During the js and html load. I have to put loader. so can I implement that any idea.

How do I have AngularJS show a loading spinner until the data has finished loading?

Currently data is come from local array.

1

2 Answers 2

2

You can make a directive, inject there http service and watch on its request pending:

(function() {
    'use strict';
    angular
        .module('yourApp')
        .directive('loader', loader);

    /**
     * Defines loading spinner behaviour
     *
     * @param {obj} $http
     * @returns {{restrict: string, link: Function}}
     */
    function loader($http) {
        return {
            restrict: 'A',
            link: function(scope, element, attributes) {
                scope.$watch(function() {
                    return $http.pendingRequests.length;
                }, function(isLoading) {
                    if (isLoading) {
                        $(element).show();
                    } else {
                        $(element).hide();
                    }
                });
            }
        };
    }
})();

And use it:

<span class="spinner" data-loader></span>
Sign up to request clarification or add additional context in comments.

Comments

0

You can simply add a "hide" class on loading image by default and on ng-click remove that "hide". After getting successful you can again add "hide" class. I think its not a big deal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.