A nice lib to show an overlay loading indicator.
npm i @code-workers.io/ngx-loader
Import the NgxLoaderModule in your app.module.ts
import { NgxLoaderModule } from '@code-workers.io/ngx-loader';
@NgModule({
imports: [
NgxLoaderModule
]
})
export class AppModule { }
<ngx-loader [show]='loading$ | async' [loaderTemplate]="myloader">
<ng-template>
<div> Some content I want to show</div>
</ng-template>
</ngx-loader>
<ng-template #myloader> <my-spinner> </my-spinner> </ng-template
Optionally you can pass a config object to the module to customize a global loader component.
import { NgxLoaderModule } from '@mikelgo/ngx-loader';
@NgModule({
imports: [
NgxLoaderModule.forRoot({
loaderComponent: MyCustomLoaderComponent,
backdropClass: 'my-custom-backdrop-class'
})
]
})
export class AppModule { }
Finally you will use it like this:
<ngx-loader [show]='loading$ | async'>
<ng-template>
<div> Some content I want to show</div>
</ng-template>
</ngx-loader>
Alternativly instead of using the ngx-loader
component you can use a structural directive:
<div *ngxLoader="data; let result; loaderTemplate: myloader">
<div >{{ result | json }}</div>
</div>
NgxLoaderComponent
show
[boolean]: condition to hide or show the componentloaderTemplate
[TemplateRef]: template to render a custom loaderbackdropClass
[string]: CSS class to apply for the backdrop background
NgxLoaderConfig
loaderComponent
[Type]: component to render a custom loaderbackdropClass
[string]: CSS class to apply for the backdrop background
Version 1.x.x is compatible with Angular 13.x.x.
Run nx test ngx-loader
to execute the unit tests.