Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在AnguarJS中重写$exceptionhander以使用TB3将异常重定向到自定义模式+_Javascript_Angularjs_Twitter Bootstrap_Scope - Fatal编程技术网

Javascript 在AnguarJS中重写$exceptionhander以使用TB3将异常重定向到自定义模式+

Javascript 在AnguarJS中重写$exceptionhander以使用TB3将异常重定向到自定义模式+,javascript,angularjs,twitter-bootstrap,scope,Javascript,Angularjs,Twitter Bootstrap,Scope,我试图通过这个网站上的一些答案,用factory覆盖$exceptionHandler。我的目标是重定向angular中发生的每个异常,无论是内部异常还是自定义异常,都应该使用twitter bootstrap3将其显示在自定义模式窗口上 myApp.factory('$exceptionHandler',function ($injector) { return function (exception, cause) { var items = {"err": exception.mess

我试图通过这个网站上的一些答案,用factory覆盖$exceptionHandler。我的目标是重定向angular中发生的每个异常,无论是内部异常还是自定义异常,都应该使用twitter bootstrap3将其显示在自定义模式窗口上

myApp.factory('$exceptionHandler',function ($injector) {
return function (exception, cause) {
  var items = {"err": exception.message};
    var modal1 = $injector.get('$modal');
  var myModal = modal1.open({
          templateUrl: 'app/js/other/templates/modal.html',
          controller: ModalInstanceCtrl,
          resolve: {
            values: function(){
                return items;
                }
          }
        });
    myModal.result.then(function (selectedItem) {
        }, function () {
            alert('Modal dismissed at: ' + new Date());
            console.log('Modal dismissed at: ' + new Date());
        });


};  

});
为了避免循环依赖,我不得不使用$injector。 控制器如下所示

var ModalInstanceCtrl =function ($scope,$modalInstance,items) {
$scope.msg.items = items;
}]);
现在问题出现在这里,我的模态被正确打开,但是我传递的错误没有被渲染。
由于将$exceptionHandler实现为factory,因此如何为自定义模式窗口提供范围。

您可以使用。它可以注入工厂,并在任何地方都可以使用。

感谢您的快速回复,但不幸的是,在我的情况下,这不起作用,因为我使用$translate服务进行本地化,这会使$translate显示循环依赖性。未捕获错误:[$injector:cdep]找到循环依赖项:$exceptionHandler