Loading animation for AngularJS
Used the SVG loading animations from this Pen by Aurer.
This module can be used in any version of Angular (see the Plunk below). All major browsers, except IE, are supported. Template 9, the default and now using CSS animations, is supported in IE10+ and the other templates are not supported in IE.
bower install ng-loaders
angular.module('app',['ngLoader']);
<link rel="stylesheet" href="/bower_components/ngLoader/ngLoader.min.css">
OR
@import "bower_components/ngLoader/ngLoader.min.css";
<script src="bower_components/ngLoader/ngLoader.min.js"></script>
<loader
working="scopeWorkingVariable"
disable-background="true"
message="scopeMessageVariable"
template="9">
</loader>
This loader can be used in many instances, one in which being for AJAX requests using Anuglar's $http service.
Set your scope variable to true before the request and in the finally
condition of the promised returned.
Example plunk can be found here.
$scope.working = true;
$scope.message = 'Loading...'
$http.get('<api endpoint>').then(
function(success) {
console.log('Success! ' + success);
},
function(error) {
console.error('Error! ' + error);
}
)['finally'](function() {
$scope.working = false;
});
Only the working
attribute is required.
Attribute | Default | Accepted Values |
---|---|---|
working | name of scope variable | Any valid scope variable |
disable-background | false | true or false |
message | undefined | Any string |
template | 9 | Any number 1-9 |
Styles of the loader can be updated / modified by targeting the loader-content
class.