Giter VIP home page Giter VIP logo

angularjs-loader's Introduction

angularjs-loader

Simple AngularJS module that allows the application to act differently when something is loading or when this thing is loaded.

##Installation

Step 1 : Add the source js to your project

<!-- index.html -->
...
<script type="text/javascript" src="xd-loader.js"></script>
...

Step 2 : Load the module in your angular application

//app.js
angular.module('myApp', ['xd.loader']);
...

Usage

First, be sure to inject the "loader" service. Then, before executing a bunch of code that takes a little time, just call loader.loading('aCustomIdToIdentifyThisLoadingProcess');. This call append to the $rootScope a boolean variable to the object "loader" for each loading called (with a different id). This variable is true if the process is still loading, false otherwise. Further in your code, when the loading process is finished, be sure to call loader.loaded('aCustomIdToIdentifyThisLoadingProcess') with the same id as before.

Example

Loading a database of user from a distant server can take some time and thus making your application "lagging" in the eyes of your visitors. Putting a simple loading gif is a good thing to tell your visitors your application is loading.

// controllers.js
function myController($scope,loader,distantDatabase)
{
    $scope.users = [];
    loader.loading('users'); // we say the users are loading
    // Fetching users, can take a while
    distantDatabase.query({entity:'users'},function(data){
        console.log(data);
        $scope.users = data;
        loader.loaded('users'); // ok, the users are loaded
    });
}
<!-- index.html -->
<table ng-hide="loading.users">
<tr ng-repeat="user in users">
    <td>{{user.name}}</td>
    <td>{{user.email}}</td>
</tr>
</table>
<div class="loading" ng-hide="!loading.users">
    <img src="img/loading.gif"/>
</div>

In this example, the loading gif will be displayed while the users are loading and hidden when they are loaded. In the other hand, the table with the users (initially empty) will be hidden while the users are loading and displayed once the process is complete.

angularjs-loader's People

Contributors

xavierdubuc avatar

Watchers

James Cloos avatar Aswath avatar

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.