1

问题:我正在使用 Ionic 1 尝试使用 Ionic Cloud 设置推送通知。我收到以下错误:

**Error: [$injector:unpr] Unknown provider: ionic.cloudProvider <- ionic.cloud <- welcomeCtrl**
ionic.bundle.js:26794 Error: [$injector:unpr] Unknown provider: ionic.cloudProvider <- ionic.cloud <- welcomeCtrl
http://errors.angularjs.org/1.5.3/$injector/unpr?p0=ionic.cloudProvider%20%3C-%20ionic.cloud%20%3C-%20welcomeCtrl
    at ionic.bundle.js:13438
    at ionic.bundle.js:17788
    at Object.getService [as get] (ionic.bundle.js:17941)
    at ionic.bundle.js:17793
    at getService (ionic.bundle.js:17941)
    at injectionArgs (ionic.bundle.js:17965)
    at Object.instantiate (ionic.bundle.js:18007)
    at $controller (ionic.bundle.js:23412)
    at Object.self.appendViewElement (ionic.bundle.js:59900)
    at Object.render (ionic.bundle.js:57893)(anonymous function) @ ionic.bundle.js:26794

我的 app.js:

    angular.module('app', [
                'ionic',
                'ionic.cloud',
...

我正在注入 ionic.cloud。

.config(function($ionicConfigProvider, $ionicCloudProvider) {
    // Set tabs always to load on top
    $ionicConfigProvider.tabs.position('top');

  $ionicCloudProvider.init({
    "core": {
      "app_id": "(my app id was here)"
    },
    "push": {
      "sender_id": "(FCM sender id was here)",
      "pluginConfig": {
        "ios": {
          "badge": true,
          "sound": true
        },
        "android": {
          "iconColor": "#343434"
        }
      }
    }
  });
});

我的配置设置正确。

然后在我的 index.html 中,我有:

  <script src="lib/ionic/js/ionic.bundle.js"></script>
  <!-- ionic cloud -->
  <script src="lib/ionic.cloud.min.js"></script>

最后在我的控制器中,我有:

angular.module('app.controllers')
.controller('welcomeCtrl', ['$scope', '$stateParams', 'UserService', '$cordovaDevice', '$cordovaCapture','$cordovaFileTransfer', '$cordovaGeolocation', '$location', '$timeout','$state', '$ionicHistory', 'ionic.cloud',
function ($scope, $stateParams, UserService, $cordovaDevice, $cordovaCapture, $cordovaFileTransfer, $cordovaGeolocation, $location,$timeout,$state, $ionicHistory, $ionicPush) {

你会看到我正在注入 'ionic.cloud'$ionicPush

我已经在 chrome 设备调试中验证了资源在那里。我跟着 Ionic cloud docs 到了 T,但一直收到这个错误。

有人有想法么?

谢谢!

4

1 回答 1

3

这里的问题是在你的控制器中你不必注入 ionic.cloud,它应该是

angular.module('app.controllers')
.controller('welcomeCtrl', ['$scope', '$stateParams', 'UserService', '$cordovaDevice', '$cordovaCapture','$cordovaFileTransfer', 
'$cordovaGeolocation', '$location', '$timeout','$state', '$ionicHistory', '$ionicPush',
function ($scope, $stateParams, UserService, $cordovaDevice, $cordovaCapture, $cordovaFileTransfer, $cordovaGeolocation, 
$location,$timeout,$state, $ionicHistory, $ionicPush) {

}

如果你的控制器来自不同的模块,它应该注入 ionic.cloud

angular.module('app.controllers',['ionic',
                'ionic.cloud'])
于 2016-12-07T05:13:48.143 回答