Created
June 13, 2018 13:46
-
-
Save dahool/a2f08d0f23071e144ea39ebed1c5a35a to your computer and use it in GitHub Desktop.
angular 6 snipped: attach spinner in observable
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 { NgxSpinnerService } from 'ngx-spinner'; | |
import { map, finalize } from 'rxjs/operators'; | |
import { HttpClient, HttpHeaders } from '@angular/common/http'; | |
... | |
private attachSpinner(ob : Observable<any>): Observable<any> { | |
this.spinner.show(); | |
return ob.pipe(finalize(() => { | |
this.spinner.hide() | |
})); | |
} | |
... | |
let ob = this.http.get<ServerData[]>(this.url) | |
.pipe(map((data: any) => { | |
let serverList: ServerData[] = []; | |
data.serverlist.forEach(s => { | |
serverList.push({server: s); | |
}) | |
return serverList; | |
})); | |
return this.attachSpinner(ob); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment