Git Product home page Git Product logo

moander / angular-state-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from entrecode/angular-state-loader

0.0 3.0 0.0 610 KB

Loading Spinner for UI Router (AngularJS) that is shown while loading a state's promises resolve. Can be restricted to specific state transitions. Including the optional parameters force-show and delay + the possibility to show a custom loader.

CSS 100.00%

angular-state-loader's Introduction

angular-state-loader

Loading Spinner for UI Router (AngularJS) that is automatically shown while loading a states resolves. Can be restricted to specific state transitions. Including the optional parameters force-show and delay + the possibility to show a custom loader.

Demo

Installation

Install angular-state-loader bower package:

npm install --save angular-state-loader
# or
bower install angular-state-loader --save

Add angular-state-loader.js and angular-state-loader.css dependencies to your html:

<script src="bower_modules/angular-state-loader.js" type="text/javascript"></script>
<link href="bower_modules/angular-state-loader.css" type="text/css" rel="stylesheet"/>

Add Angular module ec.stateloader as dependency to your app:

angular.module('myApp', ['ui.router', 'ec.stateloader'])
/* ... */

(Optional) Material Icon Font

To use the default Loader Template, you need Material Icons which can be included via the google CDN:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

If you do not want to use material icons, always use a custom template like explained below.

How to include

After Installing, the <state-loader>-directive is available.

Basic Loader

The Basic Loader with the default templates does not require any addional parameters, just place <state-loader></state-loader> somewhere in the template where you want to show a loader. This loader wil be displayed on every state change.

Custom Loader at runtime

If you want to have a custom loader (or do not want to use material-icons), just make sure your <state-loader>-tag is not empty:

<state-loader><h1>LOADING</h1></state-loader>

Change default template

If you want to change the default template for all loaders, you can use the stateLoaderProvider in your config.

You can either configure a template url with setTemplateUrl:

angular.module('myApp', ['ui.router', 'ec.stateloader'])
    .config(function('stateLoaderProvider') {
        stateLoaderProvider.setTemplateUrl('custom.tpl.html');   
     });

Or a template snippet with setTemplate:

angular.module('myApp', ['ui.router', 'ec.stateloader'])
    .config(function('stateLoaderProvider') {
        stateLoaderProvider.setTemplate('<div class="angular-state-loader">' +
        '<h1>LOHOHOHOHOADING!</h1></div>');
     });

Additional Properties

delay

By default, the loader will show up after 100ms of loading time and will stay until all of the state's promises are resolved. This delay can be changed with the delay property (in ms):

<state-loader delay="10000"><b>Taking longer than expected...</b></state-loader>

The above loader will show up if resolving the state's promises is taking longer than 10 seconds. A Value of 0 will instantly show the loader.

force-show

The property force-show expects a boolean and will show the loader if set to true. Note that the Loader still waits for the specified delay to be shown. This is useful when resolving promises inside the controller and not via the state's resolve.

Controller Example:

$scope.loadData = function() {
	$scope.showLoader = true;
	loadMuffins().then(function(muffins) {
		$scope.showLoader = false;
		$scope.muffins = muffins;
	});
}
$scope.loadData();

Template:

<state-loader force-show="showLoader"></state-loader>
<li ng-repeat="muffin in muffins">{{muffin}}</li>

This Loader will show up when the loadData Function is invoked. When the Promise is resolved, we can set showLoader to false to hide the loader again.

from-state

Expects a string. Restricts the loader to be shown only if coming from the given state name.

<state-loader from-state="bakery"></state-loader>

to-state

Expects a string. Restricts the loader to be shown only if going to the given state name.

<state-loader to-state="bakery.muffins"></state-loader>

Full Example

At last, here is a full example of how it can be used fully customized:

<state-loader from-state="bakery" to-state="bakery.muffins" delay="500">
<h3>Loading incredible amount of muffins!</h3>
</state-loader>

The above loader will only show if transitioning from state "bakery" to state "bakery.muffins" after 500ms loading time, showing a custom message.

CSS Classes

The Loader is wrapped in a div with the .angular-state-loader class which is by default positioned absolute with 100% width and height. By applying rotate-right to a custom element inside <state-loader>, it will.. guess what?

Demo

To run the Demo, install angular-state-loader and then run bower install inside its root folder. The index.html in the demo folder contains a small demo with different loading times (the same as the gif above).

angular-state-loader's People

Contributors

deyhle avatar felixroos avatar simon-scherzinger avatar

Watchers

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