Use the fork, Luke. PR without tests will likely not be merged.
To install this library, run:
$ npm install ng-http-loader --save / yarn add ng-http-loader
What does it do ?
This package provides an HTTP Interceptor, and some spinner components (All from SpinKit at the moment). The HTTP interceptor listens to all HTTP requests and shows a spinner / loader indicator during pending HTTP requests.
If you experience errors like below, please double check the version you use.
ERROR in Error: Metadata version mismatch for module [...]/angular/node_modules/ng-http-loader/ng-http-loader.module.d.ts, found version x, expected y [...]
Requirements - HttpClientModule
Performing HTTP requests with the
HttpClientModule API is mandatory. Otherwise, the spinner will not be fired at all.
See this blog post for an
From your Angular
;;// [...];; // <============; // <============
In your app.component.html, simply add:
Customizing the spinner
You can customize the following parameters:
- The spinner backdrop (visible by default).
- The background-color (ie. the color of the spinner itself).
- The debounce delay (ie. after how many milliseconds the spinner will be visible, if needed).
- The extra duration (ie. how many extra milliseconds should the spinner be visible).
- The minimum duration (ie. how many milliseconds should the spinner be visible at least).
- The spinner opacity.
- The spinner type.
To specify the spinner type this way, you must reference the
Spinkit const as a public property in your app.component.ts:
;; // <============
The different spinners available are referenced in this file.
Otherwise, you can reference the spinner type as a simple string:
Defining your own spinner
You can define your own spinner component in place of the built-in ones. The needed steps are:
- Create your component
- Add it to the entryComponents array in your module's configuration (not necessary anymore with ivy)
- Reference your component as a public property in your
- Reference the predefined property in the ng-http-loader component selector like this:
Requests filtering by URL, HTTP method or HTTP headers
You can filter the HTTP requests that shouldn't be caught by the interceptor by providing an array of regex patterns:
You can filter the HTTP requests by providing an array of HTTP methods (case insensitive):
You can also filter the HTTP requests by providing an array of HTTP headers (case insensitive):
Manually show and hide the spinner
You can manually show and hide the spinner if needed. You must use the
SpinnerVisibilityService for this purpose.
Sometimes, when manually showing the spinner, an HTTP request could be performed in background, and when finished, the spinner would automagically disappear.
For this reason, when calling
SpinnerVisibilityService#show(), it prevents the HTTP interceptor from being triggered unless you explicitly call
Internet explorer or Safari problem ?
Just use a real browser.
Each Spinkit component defined in SPINKIT_COMPONENTS can be used individually.