Unknown provider: $ionicAppProvider

2019-04-23 05:13发布

问题:

I get this error when I try to set GCM push's api key in app.js

Here is the code I use:

.config(['$ionicAppProvider', function($ionicAppProvider) {
    // Identify app
    $ionicAppProvider.identify({
        // The App ID for the server
        app_id: 'MY_APP_ID',
        // The API key all services will use for this app
        api_key: 'MY_API_KEY',
        //The GCM project number
        gcm_id: 'MY_GCM_PROJECT_NUMBER'
    });
  }])

回答1:

It looks like you haven't installed the ionic-service-core module and setup your app with it. You'll need to do the following:

1) Install Ionic Service Core. Run ionic add ionic-service-core on the command line for your project

2) Add this script tag to index.html

<script src="lib/ionic-service-core/ionic-core.js"></script>

3) Add the ionic.service.core module to your app.js like so:

angular.module('starter', ['ionic',
  'ionic.service.core',
  'starter.controllers'])


回答2:

Probably you have injected the ionic core service before your module. Try this:

angular.module('starter', [
  'ionic',
  'ionic.service.core',
  'your.module'
]);