Skip to content

Commit b9d6c72

Browse files
authored
Merge pull request #35 from heshanu/spinnerEmpployeeImpl
fixed spinner in pagination
2 parents 255ec10 + a1c6cff commit b9d6c72

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/app/employee/employee.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<div *ngIf="isLoading">
2+
<mat-spinner></mat-spinner>
3+
</div>
4+
5+
<div *ngIf="!isLoading && errorMessage">
6+
<h1>Error</h1>
7+
<p>{{ errorMessage }}</p>
8+
</div>
19

210
<div class="mat-elevation-z8">
311
<table mat-table [dataSource]="dataSource">

src/app/employee/employee.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { MatTableDataSource } from '@angular/material/table';
1111
})
1212
export class EmployeeComponent implements OnInit, AfterViewInit {
1313

14+
errorMessage!: string;
15+
isLoading: boolean = true;
1416
employeeList: EmployeeInterface[] = [];
1517

1618
@ViewChild(MatPaginator) paginator!: MatPaginator;
@@ -30,13 +32,17 @@ export class EmployeeComponent implements OnInit, AfterViewInit {
3032
}
3133

3234
public getAllEmployees() {
35+
this.isLoading = true;
3336
this.employeeService.getEmployees()
3437
.subscribe((data: EmployeeInterface[]) => {
3538
this.employeeList = data;
3639
this.dataSource.data = this.employeeList;
40+
this.isLoading = false;
3741
console.log('Fetched data:', this.employeeList); // Debugging line
3842
}, error => {
39-
console.error('Error fetching employees:', error); // Debugging line
43+
console.error('Error fetching employees:', error);
44+
this.errorMessage=error; // Debugging line
4045
});
46+
this.isLoading = false;
4147
}
4248
}

0 commit comments

Comments
 (0)