Skip to content

Instantly share code, notes, and snippets.

@bbachi
Created 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/ebd4c05d679b307efd36100d1ac90435 to your computer and use it in GitHub Desktop.
Save bbachi/ebd4c05d679b307efd36100d1ac90435 to your computer and use it in GitHub Desktop.
new way pipe observale operators
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