【发布时间】:2016-12-24 14:33:15
【问题描述】:
我在理解 HTTP 承诺链方面需要帮助。
我正在尝试以下场景:
public class Serv1 extends IServ1 {
public HelpMe() : ng.IHttpPromise<any> {
$http.post(something) -> function(somethingResult) {
// I want to return this promise from this method and use it outside
$http.get(somethingResult)
}
}
}
在我的其他服务中,我想使用Serv1.HelpMe 方法:
public class Serv2 extends IServ2 {
public UseHelpMePromise() {
var scope = this;
this.serv1.HelpMe() -> function(resultOfInnerHelpMePromise){
scope.doLogic(resultOfInnerHelpMePromise)
}
}
}
我希望你能帮助我并告诉我应该使用哪些关键字来代替上面代码中使用的“->”。
我应该使用.then 还是应该使用.success?
另外,如果我想返回内部promise(GET方法promise),我应该什么时候在HelpMe方法中加入return语句?
最后我应该使用.catch / .error 还是不使用它们?
【问题讨论】:
标签: javascript angularjs typescript promise