0

您好,我在尝试解决问题时遇到了一些麻烦"unknown provider",我分享了一些代码,以便您可以帮助我找出问题所在:

angular
   .module('ngNewDrupal', ['ng', 'ngResource'])
   .provider('$newDrupal', function() {
     var provider = this;
     this.defaults = { [...] 
     };
     this.$get = ['$log', '$resource', function ($log, $resource) {
       var forEach = angular.forEach;
       function getResource(name, params) {
         /*switch (name) {
         }*/
       }
       function getRoute(url) {
         return provider.defaults.host + url;
       }
       var NewDrupal = function () {
       };
       [...]
       return NewDrupal;
    }];
  });
})(window, window.angular);

在 index.module.js 中,我将 ngNewDrupal 添加到

angular
    .module('app', [

例如,在我的 xxx.components.js 中

angular
  .module('app')
  .component('rendition', rendition());
  function rendition() {
    return {
      templateUrl: 'app/components/rendition/rendition.html',
      controller: renditionController,
      controllerAs: 'rd'
    };
    function renditionController($log, $newDrupal, $stateParams, $http) {
      var rd = this;
      var Drupal = new $newDrupal();

最后我通过 'xxx.config.js' 向我的 $newDrupal 添加了一些操作,例如

angular
  .module('app')
  .config(config);
  function config($newDrupal) {
  $newDrupal.defaults.actions.getMyPublication = {
    webservice: { url: '/export_rest/my_publication' },
    type: 'GET',
    params: {
      _format: 'json',
      cache: true,
      isArray: true
    }
  };

但是它发送给我:

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:unpr] Unknown provider: $newDrupal
http://errors.angularjs.org/1.5.8/$injector/unpr?p0=%24newDrupal
    at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
    at http://192.168.50.100:3000/bower_components/angular/angular.js:4511:19
    at getService (http://192.168.50.100:3000/bower_components/angular/angular.js:4664:39)
    at injectionArgs (http://192.168.50.100:3000/bower_components/angular/angular.js:4688:58)
    at Object.invoke (http://192.168.50.100:3000/bower_components/angular/angular.js:4710:18)
    at runInvokeQueue (http://192.168.50.100:3000/bower_components/angular/angular.js:4611:35)
    at http://192.168.50.100:3000/bower_components/angular/angular.js:4620:11
    at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
    at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
    at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=app&p1=Error%3A%20%…92.168.50.100%3A3000%2Fbower_components%2Fangular%2Fangular.js%3A4523%3A19)
    at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
    at http://192.168.50.100:3000/bower_components/angular/angular.js:4511:19
    at getService (http://192.168.50.100:3000/bower_components/angular/angular.js:4664:39)
    at injectionArgs (http://192.168.50.100:3000/bower_components/angular/angular.js:4688:58)
    at Object.invoke (http://192.168.50.100:3000/bower_components/angular/angular.js:4710:18)
    at runInvokeQueue (http://192.168.50.100:3000/bower_components/angular/angular.js:4611:35)
    at http://192.168.50.100:3000/bower_components/angular/angular.js:4620:11
    at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
    at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
    at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=app&p1=Error%3A%20%…92.168.50.100%3A3000%2Fbower_components%2Fangular%2Fangular.js%3A4523%3A19)
    at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
    at http://192.168.50.100:3000/bower_components/angular/angular.js:4640:15
    at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
    at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
    at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
    at doBootstrap (http://192.168.50.100:3000/bower_components/angular/angular.js:1758:20)
    at bootstrap (http://192.168.50.100:3000/bower_components/angular/angular.js:1779:12)
    at angularInit (http://192.168.50.100:3000/bower_components/angular/angular.js:1664:5)
    at HTMLDocument.<anonymous> (http://192.168.50.100:3000/bower_components/angular/angular.js:31763:5)
    at fire (http://192.168.50.100:3000/bower_components/jquery/dist/jquery.js:3187:31)

我没有找到需要修改的内容和位置。

4

1 回答 1

0

正确的答案是改变

function config($newDrupal)

进入

function config($newDrupalProvider)在每个 xxx.config.js 文件中。

于 2016-11-23T12:45:12.843 回答