Skip to content

Commit cf601a9

Browse files
committed
Angular NgRx Course
1 parent 66994ce commit cf601a9

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

server/get-courses.route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function getAllCourses(req: Request, res: Response) {
1313

1414
res.status(200).json({payload:Object.values(COURSES)});
1515

16-
}, 1500);
16+
}, 1000);
1717

1818

1919

src/app/app.component.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ main {
1515
outline:none;
1616
}
1717

18+
19+
.spinner-container {
20+
width: 100%;
21+
margin-top: 100px;
22+
}
23+
24+

src/app/app.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
</button>
2929
</mat-toolbar>
3030

31+
<div class="spinner-container" *ngIf="loading">
32+
33+
<mat-spinner></mat-spinner>
34+
35+
</div>
36+
3137
<router-outlet></router-outlet>
3238

3339
</mat-sidenav-container>

src/app/app.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
22
import {select, Store} from "@ngrx/store";
33
import {Observable} from "rxjs";
44
import {map} from 'rxjs/operators';
5-
import {Router} from '@angular/router';
5+
import {NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router} from '@angular/router';
66

77
@Component({
88
selector: 'app-root',
@@ -11,14 +11,32 @@ import {Router} from '@angular/router';
1111
})
1212
export class AppComponent implements OnInit {
1313

14+
loading = true;
1415

1516
constructor(private router: Router) {
1617

1718
}
1819

1920
ngOnInit() {
2021

21-
22+
this.router.events.subscribe(event => {
23+
switch (true) {
24+
case event instanceof NavigationStart: {
25+
this.loading = true;
26+
break;
27+
}
28+
29+
case event instanceof NavigationEnd:
30+
case event instanceof NavigationCancel:
31+
case event instanceof NavigationError: {
32+
this.loading = false;
33+
break;
34+
}
35+
default: {
36+
break;
37+
}
38+
}
39+
});
2240

2341
}
2442

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {RouterState, StoreRouterConnectingModule} from '@ngrx/router-store';
2020

2121
import {EffectsModule} from '@ngrx/effects';
2222
import {EntityDataModule} from '@ngrx/data';
23+
import {MatProgressSpinnerModule} from '@angular/material';
2324

2425

2526
const routes: Routes = [
@@ -47,6 +48,7 @@ const routes: Routes = [
4748
MatMenuModule,
4849
MatIconModule,
4950
MatSidenavModule,
51+
MatProgressSpinnerModule,
5052
MatListModule,
5153
MatToolbarModule,
5254
AuthModule.forRoot()

0 commit comments

Comments
 (0)