Last active
October 21, 2020 13:28
-
-
Save keithstric/559ca6a5a965b0a63696c8dc1604472c to your computer and use it in GitHub Desktop.
Loading spinner app.component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Loading spinner --> | |
<div *ngIf="loading" class="loading-container flex-content-center"> | |
<mat-progress-spinner | |
color="primary" | |
mode="indeterminate"> | |
</mat-progress-spinner> | |
</div> | |
<!-- the application --> | |
<div class="site-container"> | |
<div class="site-header"> | |
<app-header></app-header> | |
</div> | |
<div class="site-content"> | |
<router-outlet></router-outlet> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import 'variables'; | |
.loading-container { | |
display: flex; | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100vw; | |
height: 100vh; | |
background-color: rgba(0,0,0,0.7); | |
z-index: 5; | |
} | |
.site-container { | |
font-size: 14px; | |
font-family: Roboto, "Helvetica Neue", sans-serif; | |
height: 100vh; | |
background: #f1f1f1; | |
overflow: hidden; | |
.site-header { | |
height: 64px; | |
} | |
.site-content { | |
height: calc(100vh - 65px); | |
padding: 0 15px; | |
overflow: auto; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit} from '@angular/core'; | |
import {delay} from 'rxjs/operators'; | |
import {LoadingService} from './layout/services/loading/loading.service'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent implements OnInit { | |
title = 'angular-boilerplate'; | |
loading: boolean = false; | |
constructor( | |
private _loading: LoadingService | |
){ } | |
ngOnInit() { | |
this.listenToLoading(); | |
} | |
/** | |
* Listen to the loadingSub property in the LoadingService class. This drives the | |
* display of the loading spinner. | |
*/ | |
listenToLoading(): void { | |
this._loading.loadingSub | |
.pipe(delay(0)) // This prevents a ExpressionChangedAfterItHasBeenCheckedError for subsequent requests | |
.subscribe((loading) => { | |
this.loading = loading; | |
}); | |
} | |
} |
I think that I'm looking for something like https://github.com/MZanggl/promistate but compatible with observables.
How do you think I compare versus your solution ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @keithstric so I read your blog on medium and I have a few misunderstandings:
How to tie a spinner to a specific request?
Essentially the only elegant solution that I know would be https://github.com/posva/vue-promised but I haven't found similar solution on the Angular world. Do all production ready Angular apps are cluttered by checking isLoading booleans ?