如何取消angular2中所有待处理的承诺。我知道承诺不可取消,但有没有解决这个问题?如何在注销时取消所有待处理的请求。
API-服务
get(url: string) {
let that = this;
let getPromise = new Promise((resolve, reject) => {
this
.httpService
.get(url)
// ...and calling .json() on the response to return data
.map((res: Response) => res.json())
.subscribe(response => {
resolve(response);
}, (error) => {
console.log(error);
reject(that.handleError(error));
}, () => {
console.log('API Subscription Complete!');
});
});
return getPromise;
}
组件的服务
fetchData(url) {
return new Promise(resolve => {
this
.apiService
.get(url)
.then(response => {
resolve(response);
}).catch(error=>{
console.log(error);
});
});
}