我正在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
我在这里缺少什么?
答案 0 :(得分:-1)
当你必须在controller/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'),
});