P
P
Pogran2017-01-13 09:55:07
JavaScript
Pogran, 2017-01-13 09:55:07

How to cancel a request to receive data?

I have a data loading method in the service

getSpend(months : number[]) {
        return this.http.get("assets/fake/fake-report-spend.json")
            .map((data: Response) => data.json().data)
            .concatMap((array) => Observable.from(array))
            .filter((data: {month: number, spend: number}) => months.indexOf(data.month) != -1)
            .catch((error : any) => Observable.throw(error))
            .delay(2500);
    }

and here is the output
this.reportService.getSpend(this.selectedMonthsKeys)
            .subscribe(
                data => {
                    this.data.push(data.spend);
                },
             )

The point is that the method is called when the user changes the value in select2. And it turns out the data overlay. At me not up to the end the first request fulfills and data from other request at once are superimposed on its place. And I want the previous request to be canceled if it has already partially loaded the data (this.data.push(data.spend)) , then clear them

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zakharov Alexander, 2017-01-13
@Pogran

It's called angular cancel request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question