在AngularJS中更改承诺的状态?

时间:2015-06-29 06:26:35

标签: angularjs promise

我有如下服务;使用.cancel()方法解析承诺以取消它。问题是,一旦我调用.cancel(),承诺就会得到解决,然后所有后果调用都会失败。

无论如何我能解决这个问题吗?从resolved更改回pending

.service('MyService', function($http, $q) {

  this.canceller = $q.defer()
  this.my_func = function(params) {
    params.timeout = canceller.promise
    return $http.get(url, params)
  }

  this.cancel = function () {
    this.canceller.resolve('Cancel my_func ...');
  }
})

0 个答案:

没有答案
相关问题