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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -