Schuere
Schuere

Reputation: 1649

Unknown provider: $ionicPopup

I'm implementing Global Error Handling inside an Ionic application. I want to receive an IonicPopup telling me that an error occurred. For the errorExceptionHandler I created a new config based on an existing solution that holds an alert as Global Error Handling.

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
            };
        }]);
    })

This immediately resulted into the following error.

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:unpr] Unknown provider: $ionicPopup

What am I missing here?

Upvotes: 0

Views: 820

Answers (1)

Thalaivar
Thalaivar

Reputation: 23632

Why are you injecting $ionicPopup inside a config function when you have to inject it in a controller/factory/service

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

config function accepts providers, you can inject only a provider,if at all you need it... you could do something like below.

angular.module('myApp').config(function () {
    var injector = angular.injector(['ng']),
        ionicPopup= injector.get('$ionicPopup'),
});

Upvotes: -1

Related Questions