通过$ translate调用语言更改会导致“检测到断开的拦截器:拒绝时未提供配置对象”:angular-loading-bar

时间:2016-03-29 11:30:18

标签: angularjs translate

使用以下方法更改语言的调用会导致错误:

$translate.use(language);

控制台中的错误:

angular.js:13294 SyntaxError: Unexpected string
at Object.parse (native)
at fromJson (http://127.0.0.1:8080/bower_components/angular/angular.js:1285:14)
at defaultHttpResponseTransform (http://127.0.0.1:8080/bower_components/angular/angular.js:10175:16)
at http://127.0.0.1:8080/bower_components/angular/angular.js:10266:12
at forEach (http://127.0.0.1:8080/bower_components/angular/angular.js:321:20)
at transformData (http://127.0.0.1:8080/bower_components/angular/angular.js:10265:3)
at transformResponse (http://127.0.0.1:8080/bower_components/angular/angular.js:11054:21)
at processQueue (http://127.0.0.1:8080/bower_components/angular/angular.js:15627:28)
at http://127.0.0.1:8080/bower_components/angular/angular.js:15643:27
at Scope.$eval (http://127.0.0.1:8080/bower_components/angular/angular.js:16895:28)(anonymous function) @ angular.js:13294(anonymous function) @ angular.js:10007processQueue @ angular.js:15635(anonymous function) @ angular.js:15643Scope.$eval @ angular.js:16895Scope.$digest @ angular.js:16711Scope.$apply @ angular.js:17003done @ angular.js:11324completeRequest @ angular.js:11522requestLoaded @ angular.js:11463
2016-03-29 16:53:57.589 angular.js:13294 Broken interceptor detected: Config object not supplied in rejection:

不确定是什么问题。如果有人知道解决方案,请告诉我。

2 个答案:

答案 0 :(得分:2)

想通了。问题出在本地化字符串文件中,在新添加的键值对之后有一个逗号丢失。愚蠢的错误,但角度的错误完全不同。enter image description here

答案 1 :(得分:1)

查看源代码:

'responseError': function(rejection) {
    if (!rejection || !rejection.config) {
        $log.error('Broken interceptor detected: Config object not supplied in rejection:\n https://github.com/chieffancypants/angular-loading-bar/pull/50');
        return $q.reject(rejection);
    }  

它会在拦截器错误处理程序中抛出此错误,这可能意味着您正在执行失败的请求。您是否可以打开网络选项卡,看看切换语言时发生了什么?这个问题应该在那里可见