Angular.provider未知

时间:2016-11-22 11:09:50

标签: javascript angularjs angular-services angular-providers

您好我在尝试解析"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)

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

1 个答案:

答案 0 :(得分:0)

正确的答案是改变

function config($newDrupal)

进入

每个xxx.config.js文件中都有

function config($newDrupalProvider)