Angular2: Cancel Http requests that are in a loop

Viewed 2503

I have a series of Http calls that are made by looping through the gadgets. Is there a way to abort all the requests

      for (let gadget of gadgets) {
               this.userService.getGadgetsData(gadget.Id, gadget.Name).subscribe(gadgetsData => {   
    });
}

My service code in component.service.ts

@Injectable()
export class UserService {
    constructor(public _http: Http) { }
 getGadgetsData() {

        return this._http.get(this._dashboards, { headers: this.getHeaders() })
            .map((res: Response) => res.json());
    }

}
2 Answers
Related