可能未处理的拒绝:{} [英] Possibly unhandled rejection: {}

查看:71
本文介绍了可能未处理的拒绝:{}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了错误:

可能未处理的拒绝:{}

Possibly unhandled rejection: {}

我阅读了本主题中的解决方案: Angular 1.6.0: 可能是未处理的拒绝";错误

I read the solution in this topic : Angular 1.6.0: "Possibly unhandled rejection" error

我尝试过,但是我不知道我将固定代码放在哪里,请帮助我,谢谢 谢谢大家!

i tried But i dont know where i put fixed code, please kindly help me, thanks Thanks all !

推荐答案

第一个选择就是通过在$ qProvider配置中使用errorOnUnhandledRejections禁用错误来隐藏错误:

First option is simply to hide an error by disabling them with errorOnUnhandledRejections in $qProvider configuration:

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

只会关闭日志记录.错误本身仍将

BUT this will only switch off logging. The error itself will remain

在这种情况下更好的解决方案将是-使用.catch()方法处理拒绝:

The better solution in this case will be - handling a rejection with .catch() method:

service.doSomething()
 .then(function (response) {
   //normal processing
})
 .catch(function (err) {
     console.log(err);
     throw err;
});

有用链接:

  • Promise
  • Migrating Angular 1.5 to 1.6
  • $http: remove deprecated callback methods: 'success()/error()'

这篇关于可能未处理的拒绝:{}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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