My service is set up to make an http get request that responds with a list of products:
import 'rxjs/Rx';
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
@Injectable()
export class ProductService{
constructor(private _http:Http) {}
getData() {
return this._http.get(`URL GOES HERE`)
.map(res => res.json());
}
}
This component uses the service:
import { Component, OnInit } from '@angular/core';
import { ProductService } from './product.service';
class ProductListComponent implements OnInit {
constructor(public _productService: ProductService) {}
ngOnInit() {
this._productService.getData()
.subscribe(data => this.products = data,
err => console.log(err));
}
}
I am looking for a way to handle errors. If the service encounters an error, I want to refresh it:
this._productService.getData()
.subscribe(data => this.products = data,
err => { **recall this._productService.getData()** }
Thank you for all responses