Last active
February 11, 2019 18:44
-
-
Save bbachi/35ca823946a428396984c2b1056506cd to your computer and use it in GitHub Desktop.
from chaining to piping
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
import { Component } from '@angular/core'; | |
import { Observable } from 'rxjs/Observable'; | |
import 'rxjs/add/observable/retry'; | |
import 'rxjs/add/operator/map'; | |
import { HttpClient } from '@angular/common/http'; | |
@Injectable() | |
export class AppService implements OnInit { | |
constructor(private http: HttpClient) {} | |
ngOnInit(){ | |
this.appConfig = this.http.get(this.configUrl); | |
} | |
get(url: string): Observable<any> { | |
let headers = new Headers({'Content-Type' : 'application/json'}); | |
let options = new RequestOptions({headers: headers}); | |
return this.http.get(this.rootUrl+url, options) | |
.retry(3), // Retry up to 3 times before failing | |
.map((response: Response) => <any> response.json()), | |
.catch(err => of([])) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment