NgxProgress is customizable Angular library for showing a progress bar during http request and/or routing change (or all you want) and prevent user interaction.
If you use npm
npm install @kken94/ngx-progress --save
If you use yarn
yarn add @kken94/ngx-progress
Choose the most suitable module for you.
There are two modules:
- NgxProgressModule (manage progress bar by yourself)
- NgxProgressHttpModule (import progress bar and intercept http requests)
Warning: to use http module import that in your app.module.ts, then import NgxProgressModule where you want to use progress bar.
import { NgxProgressHttpModule } from '@kken94/ngx-progress';
@NgModule({
declarations: [AppComponent],
imports: [
...
NgxProgressHttpModule,
...
],
bootstrap: [AppComponent],
})
export class AppModule {}
and place it into the element you want to cover.
Note: If you want to use overlay be sure that the parent element has position:relative
Overlay works with position:absolute
, top:0
, left:0
<div style="position: relative">
<ngx-progress></ngx-progress>
<table></table>
</div>
- NgxProgress supports multiple requests. If during the bar progress another request is fired, bar will not reset and keep going until all requests are completed.
- NgxProgress can be instantiated multiple times. Only the deepest one will be displayed
You can filter the HTTP requests that would like to be avoided by the interceptor by providing an array of regex patterns:
import { NgxProgressHttpModule } from '@kken94/ngx-progress';
@NgModule({
declarations: [AppComponent],
imports: [
...
NgxProgressHttpModule.forRoot(['auth', '[a-zA-Z]']),
...
],
bootstrap: [AppComponent],
})
export class AppModule {}
Input | Description | Default value |
---|---|---|
color |
#0984e3 |
|
showSpinner |
true |
|
showBar |
true |
|
indeterminate |
Indeterminate style like Material | false |
barHeight |
1px |
|
spinnerDiameter |
10px |
|
initialValue |
From 1 to 100 | undefined |
overlay |
Show overlay that prevent user click | true |
overlayValue |
From 0 to 1 | 1 |
spinnerSpeed |
From 1 to 10 | 4 |
NgxProgress provides also some emitters.
You have to inject NgxProgressService
and subscribe end$
or start$
In NgxProgressService
there are four methods:
start()
: start bar if no request is in progress or add new request to queue of the bar already shownend()
: complete the bar if all requests are finishedreset()
: force bar to start from zeroterminate()
: force bar to terminate even if some requests are in progress
In NgxProgressService
:
enable()
: enable bars if it has been previously disableddisable()
: disables all the bars that will not be shown until the next enabling
and provide isEnabled
variable to know if progress bar is enabled.
Enabled by default.
This project is licensed under the MIT License - see the LICENSE.md file for details
Offer me a coffee 😁