假设我的模块中有这个:
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/