Created
February 11, 2019 18:44
-
-
Save bbachi/ebd4c05d679b307efd36100d1ac90435 to your computer and use it in GitHub Desktop.
new way pipe observale operators
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 { HttpClient } from '@angular/common/http'; | |
import { retry, map, catchError } from 'rxjs/operators'; | |
@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).pipe( | |
retry(3), // Retry up to 3 times before failing | |
map((response: Response) => <any> response.json()), | |
catchError(err => of([])) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment