Skip to content

Instantly share code, notes, and snippets.

@bbachi
Last active February 11, 2019 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbachi/35ca823946a428396984c2b1056506cd to your computer and use it in GitHub Desktop.
Save bbachi/35ca823946a428396984c2b1056506cd to your computer and use it in GitHub Desktop.
from chaining to piping
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