无法调用未定义的方法"then" [英] Cannot call method 'then' of undefined

查看:59
本文介绍了无法调用未定义的方法"then"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会出现无法调用未定义的'then'方法":

Why am I getting 'cannot call method 'then' of undefined':

http://plnkr.co/edit/yWS6hRjmZZeZMJyVA0zy?p=preview

您不能在另一个诺言的.then内解析一个诺言吗?

Can you not resolve a promise inside the .then of another promise?

如果您删除对doSomething()的调用,代码就可以正常工作,并且可以到达郊区.但是,一旦将调用添加至doSomething(),它就会失败,并显示.then undefined error.

The code works fine if you take out the call to doSomething(), and it gets the suburbs, but as soon as you add the call to doSomething() it fails with that .then undefined error.

如果doSomething的调用不在.then之外,那么对到达郊区的请求也可以使用,因此这就是为什么我导致相信与嵌入它有关的原因.

The call to doSomething also works if it's outside of the .then for the requests to get the suburbs, so that's why I'm lead to believe it's something to do with it being embedded.

谢谢

推荐答案

我看到了您的问题,并且有一个小错误.我正在给改正的矮人. http://plnkr.co/edit/vRuA5Vy8sT6BhzsaYTkl?p=preview

I saw your plunk and there is a minor error. I am giving the corrected plunker. http://plnkr.co/edit/vRuA5Vy8sT6BhzsaYTkl?p=preview

doSomething : function() {
  //your method isn't returning anything
  return $http().then();
}

这篇关于无法调用未定义的方法"then"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆