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 に答える