2016-05-15 30 views
0

私はそのような話題をたくさん見たことがありますが、解決策が見つかりませんでした。不明なプロバイダ - AngularJS

私は、このエラーのエラーを取得しています:ここで

$injector:unpr Unknown Provider

Unknown provider: restaurantsProvider <- restaurants <- restaurantsController

は私のコントローラです:

(function() { 
    'use strict'; 

    angular 
     .module('myApp') 
     .controller('restaurantsController', restaurantsController); 

    restaurantsController.$inject = ['$scope', 'restaurants']; 

    function restaurantsController($scope, restaurants) { 

     $scope.restaurants = restaurants.query(); 
    } 
})(); 

とサービスのファイル:

(function() { 
    'use strict'; 

    var restaurantsService = angular.module('restaurantsService', ['ngResource']); 

    restaurantsService.factory('restaurantsService', ['$resource', function ($resource) { 
      return $resource('/api/restaurants', {}, { 
       query: { method: 'GET', params: {}, isArray: true } 
      }); 
     }]); 
})(); 

それが何かに影響を与える場合、私は」 ASP.NETを使用しています。

答えて

2

このエラーは、角が分からないものを注入しようとしていることを示しています。私はこの問題につながっているアプリの構造を見ているいくつかの問題は、あなたが実際にあなたがあなたのrestaurantServiceアプリを注入する必要がある場所であるあなたの「て、myApp」モジュールを宣言することはありません

  1. ...があります。

    (function() { 
         'use strict'; 
    
         var restaurantsServiceApp = angular.module('restaurantsServiceApp', ['ngResource']); 
    
         restaurantsServiceApp.factory('restaurantsService', ['$resource', function ($resource) { 
           return $resource('/api/restaurants', {}, { 
            query: { method: 'GET', params: {}, isArray: true } 
           }); 
          }]); 
        })(); 
    
    (function() { 
        'use strict'; 
        var myApp = angular.module('myApp', ['restaurantsServiceApp']); 
        myApp.controller('restaurantsController', restaurantsController); 
    
        restaurantsController.$inject = ['$scope', 'restaurantsService']; 
    
        function restaurantsController($scope, restaurantsService) { 
    
         $scope.restaurants = restaurantsService.query(); 
        } 
    })(); 
    

    あなた:

  2. あなたのコントローラは、私はアプリの構造はこのような何かを見て期待「レストラン」の依存関係になりますが、サービスは実際には「restaurantsService」

と呼ばれていますserviceAppは、他のアプリに注入する前に宣言する必要があります。

+1

これはキーでした:「あなたのserviceAppは他のアプリケーションに注入する前に宣言する必要があります。」私のapp.jsでは、「restaturantsService」を追加することを忘れてしまいます。 _var myApp = angular.module( 'myApp'、['ngRoute'、** 'restaurantsService' **]); _ –

関連する問題