0

我正在 Ionic 应用程序中实现全局错误处理。我想收到一个 IonicPopup 告诉我发生了错误。对于 errorExceptionHandler,我基于现有解决方案创建了一个新配置,该解决方案将警报作为全局错误处理。

angular
  .module('MyApp', ['ionic'])
  .config(function ($provide, $ionicPopup) {
        $provide.decorator('$exceptionHandler', ['$delegate', function ($delegate) {
            return function (exception, cause) {
                $delegate(exception, cause);
                //Alert works fine
                alert(exception.message);
                //$ionicPopup will follow here
            };
        }]);
    })

这立即导致以下错误。

angular.js:68 未捕获错误:[$injector:modulerr] 无法实例化模块应用程序,原因是:错误:[$injector:unpr] 未知提供程序:$ionicPopup

我在这里想念什么?

4

1 回答 1

-1

为什么必须在配置函数中注入 $ionicPopupcontroller/factory/service

http://ionicframework.com/docs/api/service/ $ionicPopup/

config函数接受providers,你可以只注入一个提供者,如果你需要它......你可以做类似下面的事情。

angular.module('myApp').config(function () {
    var injector = angular.injector(['ng']),
        ionicPopup= injector.get('$ionicPopup'),
});
于 2016-03-29T12:40:12.583 回答