Skip to content

Instantly share code, notes, and snippets.

@pascalwhoop
Created March 20, 2017 11:50
Show Gist options
  • Save pascalwhoop/5459445dda7f1458a4cad7a50fe9f34a to your computer and use it in GitHub Desktop.
Save pascalwhoop/5459445dda7f1458a4cad7a50fe9f34a to your computer and use it in GitHub Desktop.
@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