Created
March 20, 2017 11:50
-
-
Save pascalwhoop/5459445dda7f1458a4cad7a50fe9f34a to your computer and use it in GitHub Desktop.
This file contains 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
@Component({ | |
selector: 'steak-working-spinner', | |
template: `<md-progress-spinner mode="indeterminate" *ngIf="_visible"></md-progress-spinner>`, | |
styleUrls: ['working-spinner.component.scss'] | |
}) | |
export class WorkingSpinnerComponent implements OnInit, OnDestroy { | |
private _visible: boolean; | |
private _subscription: AnonymousSubscription; | |
private _connectionCounter = 0; | |
constructor(public browserXhr: CustomBrowserXhr) { | |
} | |
ngOnInit() { | |
this._subscription = this.browserXhr.observable.subscribe(next => { | |
console.log(next.type + ' next received in spinner'); | |
switch (next.type) { | |
case 'open': | |
this._connectionCounter++; | |
break; | |
case 'load': | |
this._connectionCounter--; | |
break; | |
case 'abort': | |
this._connectionCounter--; | |
break; | |
case 'error': | |
this._connectionCounter--; | |
break; | |
} | |
this._visible = this._connectionCounter > 0; //if larger 0, its visible! otherwise hide us | |
}); | |
} | |
ngOnDestroy(): void { | |
if (!this._subscription) return; | |
this._subscription.unsubscribe(); | |
this._subscription = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment