javascript - Angular 4: abort all pending $http requests on route change -
i have dataservice
, eg.:
import { injectable } '@angular/core'; import { http } '@angular/http'; @injectable() export class dataservice { constructor(private http: http) {} getdata(): promise<any[]> { return this.http.get('/api/data') .topromise() .then(response => { const js_res = response.json(); if ( js_res.data ){ return js_res.data any[]; } else { throw new error(js_res.info || response.text); } }) .catch( err => { console.log(err); }); } }
this dataservice
called many times in each route. when user change route, many request can pending, , want abort pending requests of old route.
i'm new on angular 4, right approach?
Comments
Post a Comment