Introduction
In this article, we will learn how we can show the Loader in Angular 8 using Ngx spinner library. Ngx spinner is a library for loading spinner for Angular, which is meant to inform the user that data loading is in progress. Basically Loader is used to show the loading state of data in application.
Prerequisites
- Basic Knowledge of Angular 2 or higher
- Visual Studio Code
- Visual studio and SQL Server Management studio
- Node and NPM installed
- Bootstrap
Step 1
Create an Angular project by using the following command.
- ng new Angularloader
Step 2
Open this project in Visual Studio Code and install bootstrap by using following command
- npm install bootstrap --save
Now open styles.css file and add Bootstrap file reference. To add reference in styles.css file add this line.
- @import '~bootstrap/dist/css/bootstrap.min.css';
Step 3
Now install ngx spinner library in this project, to install ngx spinner library use the following command
- npm install ngx-spinner --save
Step 4
Now Update app.module.ts
Open app.module.ts file and add Import NgxSpinnerModule in the root module,
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppRoutingModule } from './app-routing.module';
- import { AppComponent } from './app.component';
- import { HttpClientModule } from '@angular/common/http'
- import { EmployeedetailsComponent } from './employeedetails/employeedetails.component';
- import { NgxSpinnerModule } from "ngx-spinner";
- @NgModule({
- declarations: [
- AppComponent,
- EmployeedetailsComponent
- ],
- imports: [
- BrowserModule,
- AppRoutingModule,
- HttpClientModule,
- NgxSpinnerModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }

Step 5
Now create a new component by using the following command.
- ng g c Employeedetails --spec=false
Now open employeedetails.component.ts file and import NgxSpinnerService
- import { Component, OnInit } from '@angular/core';
- import { EmployeeService } from "../employee.service";
- import { Employe } from "../employe";
- import { NgxSpinnerService } from "ngx-spinner";
- @Component({
- selector: 'app-employeedetails',
- templateUrl: './employeedetails.component.html',
- styleUrls: ['./employeedetails.component.css']
- })
- export class EmployeedetailsComponent implements OnInit {
- emp: any;
- constructor(private employeeService: EmployeeService,
- private SpinnerService: NgxSpinnerService) { }
- ngOnInit() {
- this.GetemployeeDetails();
- }
- GetemployeeDetails() {
- this.SpinnerService.show();
- this.employeeService.GetemployeeDetails().subscribe((data: any) => {
- this.emp = data;
- console.log(this.emp);
- this.SpinnerService.hide();
- });
- }
- }

Open employeedetails.component.html file and following lines
- <div>
- <div class="row" style="margin-top:10px;margin-bottom: 10px;">
- <div class="col-sm-12 btn btn-success">
- Loader in Angular Application with Dynamic Data
- </div>
- </div>
- <div class="row" style="margin-top:10px;margin-bottom: 10px;">
- </div>
- </div>
- <hr style="background-color:black" />
- <div>
- <table class="table table-dark table-striped">
- <thead>
- <tr>
- <th>Id</th>
- <th>Name</th>
- <th>Age</th>
- <th>Address</th>
- <th>City</th>
- <th>ContactNum</th>
- <th>Salary</th>
- <th>Department</th>
- </tr>
- </thead>
- <tbody>
- <tr *ngFor="let e of emp">
- <td>{{e.Id}}</td>
- <td>{{e.Name}}</td>
- <td>{{e.Age}}</td>
- <td>{{e.Address}}</td>
- <td>{{e.City}}</td>
- <td>{{e.ContactNum}}</td>
- <td>{{e.Salary}}</td>
- <td>{{e.Department}}</td>
- </tr>
- </tbody>
- </table>
- </div>
- <ngx-spinner bdColor="rgba(51, 51, 51, 0.8)" size="default" type="ball-spin-clockwise">
- <p style="color: white">Please Wait. </p>
- </ngx-spinner>











Raju VermaPosted Sep 21, 2021, 11:04 AM
ERROR in node_modules/ngx-spinner/lib/ngx-spinner.service.d.ts:33:21 - error TS2694: Namespace '"C:/Users/rajukumar.verma/My Work/iRFS (Z070061)/iRFSMain/iRFSApiVer2/NgApp/node_modules/@angular/core/core"' has no exported member '??FactoryDeclaration'. 33 static ?fac: i0.??FactoryDeclaration<NgxSpinnerService, never>;ERROR in ./node_modules/ngx-spinner/fesm2015/ngx-spinner.js 133:147-165 "export '??FactoryTarget' (imported as 'i0') was not found in '@angular/core' ERROR in ./node_modules/ngx-spinner/fesm2015/ngx-spinner.js 152:163-181 "export '??FactoryTarget' (imported as 'i0') was not found in '@angular/core' ERROR in ./node_modules/ngx-spinner/fesm2015/ngx-spinner.js 333:238-256 "export '??FactoryTarget' (imported as 'i0') was not found in '@angular/core' ERROR in ./node_modules/ngx-spinner/fesm2015/ngx-spinner.js 392:145-163 "export '??FactoryTarget' (imported as 'i0') was not found in '@angular/core' ERROR in ./node_modules/ngx-spinner/fesm2015/ngx-spinner.js 135:0-27 "export '??ngDeclareClassMetadata' (imported as 'i0') was not found in '@angular/core'
Raju VermaPosted Sep 21, 2021, 11:03 AM
Not working
Amit MohantyPosted Oct 31, 2019, 7:34 AM
Nice article
Sarathlal SaseendranPosted Oct 29, 2019, 2:49 PM
Very interesting post Sanwar.