angularjs - 解析时未打印错误,ui-router

标签 angularjs error-handling angular-ui-router

假设我的模块中有这个:

resolve: {
        user: function(UserLoader){
          return new UserLoader($stateParams.userId);
        }
      }
controller..

如你所见,我没有注入(inject) $stateparams ,因此我无法加载 Controller 和 View 。但是为什么控制台没有像其他地方一样在解析时给出任何错误呢?如果您的解决方案中有一些逻辑,那么调试可能会很痛苦。是否有可能以某种方式“打开”控制台?

最佳答案

从文档中:

$stateChangeError - fired when an error occurs during transition. It's important to note that if you have any errors in your resolve functions (javascript errors, non-existent services, etc) they will not throw traditionally. You must listen for this $stateChangeError event to catch ALL errors. Use event.preventDefault() to prevent the $UrlRouter from reverting the URL to the previous valid location (in case of a URL navigation).



您必须监听 '$stateChangeError' 事件
$rootScope.$on('$stateChangeError', 
function(event, toState, toParams, fromState, fromParams, error){ 
// an error occured, do something like $log.error(error) 
})

如果您想了解更多关于 ui-router 事件的信息,请查看 api here

关于angularjs - 解析时未打印错误,ui-router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33282555/

相关文章:

angularjs - 是否可以为同一个 View 使用两个 Controller ?最好用ui-router

javascript - 如何使用angular js将表格行添加为模板

javascript - 未知提供者 : $routeParamsProvider <- $routeParams

javascript - 我的 AngularJs 代码无法正常运行并出现此错误 - TypeError : Cannot read property '#<Object>' of undefined

asp.net - 捕获HTTP错误403.7-在ASP.NET中被禁止

C - 获取字符串检查它并使其成为 double

c++ - ofstream 指针的 vector

javascript - Angular UI Router - 具有空 Url 的抽象父状态

javascript - 动态添加数据时如何应用 ng-class(?)

javascript - 设置要在 ion-toggle 中检查的默认切换