javascript - Spinner in Angular.js -


i want use spinner can show during of rest api calls better ux. have come across many existing github projects similar things.

https://github.com/cgross/angular-busy
https://github.com/urish/angular-spinner

but i'm not able use of existing projects. think before start writing of own, want know if things i'm looking can done using these projects or other existing project.

requirement:

  1. during of rest api calls uploading images, fetching data, deleting images, etc, want show spinner background faded. once have result, can show background again , remove spinner.
  2. i want use spinner start/stop controller not html.
  3. i don't want spinner xhr requests default.

i think angular-busy demo solves of above requirements except needs promise param in html. there anyway can control start/stop dynamically controller rather giving promise.

angular-spinner demo doesn't fade out background. there way fade out background ?

can give me pointers how can solve problem ?

i create own spinner logic:

js:

app.directive('ngspinnerbar', ['$rootscope',     function ($rootscope) {         return {             link: function (scope, element, attrs) {                 // defult hide spinner bar                 element.addclass('hide');                   // count how many time requests sent server                 // when done spinner removed                 scope.counter = 0;                  $rootscope.$on('$statenetworkrequeststarted', function () {                     scope.counter++;                     element.removeclass('hide'); // show spinner bar                     //  $('body').addclass('page-on-load');                 });                  $rootscope.$on('$statenetworkrequestended', function () {                     scope.counter--;                     if (scope.counter <= 0) {                         scope.counter = 0;                         element.addclass('hide'); // show spinner bar                         //  $('body').removeclass('page-on-load'); // remove page loading indicator                     }                  });              }         };     } ]) 

html:

<div ng-spinner-bar></div> 

as can see every time send request api show spinner (css create spinning - link) , when result come send event hide spinner.

if want make things easier you, should create service send api requests (wrap $http). way can ensure every request show spinner.

edit

the first result in google gave me this - fade background in angular


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

html - Is there any way to exclude a single element from the style? (Bootstrap) -

Delphi 7 and decode UTF-8 base64 -