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 }
});
}]);
})();
如果它影響到的東西,我m使用ASP.NET。
這是一個關鍵:「您的服務應用程序需要在被注入其他應用程序之前進行聲明。」在我的app.js中,我忘了添加'restaturantsService'。 _var myApp = angular.module('myApp',['ngRoute',**'restaurantsService'**]); _ –