i have this service that is an http get request that response 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());
}
}
and this component call 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 want to manage the .error; when the service goes in error, i want to refresh the service:
this._productService.getData()
.subscribe(data => this.products = data,
err => { **recall this._productService.getData()** }
Thank for all responses