11# angular-loading-spinner
22Loading spinner for AngularJS
33
4- __ DEMO:__ https://sarsha17 .github.io/angular-spinner/
4+ __ DEMO:__ https://msarsha .github.io/angular-spinner/
55
66### Build
77Clone the repo and run ` npm install ` to install dependencies and then ` gulp ` to build;
88
9+ ### Dependencies:
10+ ` angular-animate `
11+
12+ ### Setup:
13+
14+ add spinner module as dependency
15+ ```` javascript
16+ angular .module (' app' , [' sarsha.spinner' ])
17+ ````
18+ load angular-animate in your html
19+ ```` html
20+ <script src =" https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular-animate.min.js" ></script >
21+ ````
22+
23+
924### How to use:
10- (default spinner template)
25+
26+ Use the default spinner template
1127
1228```` html
1329<div >
@@ -16,7 +32,20 @@ Clone the repo and run `npm install` to install dependencies and then `gulp` to
1632</div >
1733````
1834
19- You can place as many spinners as you like
35+ Use your own template:
36+
37+ ```` html
38+ <div >
39+ Your content here
40+ <sarsha-spinner name =" spinner1" >
41+ <div >
42+ <span >MY OWN TEMPLATE !!</span >
43+ </div >
44+ </sarsha-spinner >
45+ </div >
46+ ````
47+
48+ Place as many spinners as you like
2049```` html
2150<div >
2251 Your content here
@@ -28,8 +57,9 @@ You can place as many spinners as you like
2857</div >
2958````
3059
60+ ### Controlling the Spinners
3161
32- Control the spinner using the ` spinnerService `
62+ #### Manualy control the spinners using the ` spinnerService `
3363
3464```` javascript
3565 angular .controller (' ctrl' , function (spinnerService ){
@@ -47,15 +77,35 @@ Control the spinner using the `spinnerService`
4777 })
4878````
4979
50- You can use your own template:
80+ #### Let the ` spinnerHttpInterceptor ` control the spinners
5181
52- ```` html
53- <div >
54- Your content here
55- <sarsha-spinner name =" spinner1" >
56- <div >
57- <span >MY OWN TEMPLATE !!</span >
58- </div >
59- </sarsha-spinner >
60- </div >
82+ Add the ` spinnerHttpInterceptor ` to your module config
83+ ```` javascipt
84+ angular
85+ .module('app', [])
86+ .config(function($httpProvider){
87+ $httpProvider.interceptors.push('spinnerHttpInterceptor');
88+ })
89+ ````
90+
91+ The default behavior of the ` spinnerHttpInterceptor ` is to show and close all existing spinners.
92+
93+ You can tell it which spinner is related to the http request by adding the ` spinner ` object to the ` $http ` config.
94+
95+ The ` spinner ` object can be either a ` string ` for a single spinner or an ` Array ` for number of spinners.
96+
97+ ```` javascript
98+ angular .controller (' ctrl' , function ($http ){
99+ this .doSomething = function (){
100+ $http .get (' http://url.com' , {
101+ spinner: ' spinner1'
102+ })
103+ }
104+
105+ this .doSomething = function (){
106+ $http .get (' http://url.com' , {
107+ spinner: [' spinner1' , ' spinner2' ]
108+ })
109+ }
110+ })
61111````
0 commit comments