简体   繁体   中英

Unknown provider: $resourceProvider <- $resource with AngularJS

I have declared the following in app.js

angular.module('adminApp', ['ngGrid','ngResource']);

in data.js

angular.module('adminApp', [])
.factory('testAccountService', function ($http) {
    var TestAccount = {

in GridCtrl.js

angular.module('adminApp',[])
    .controller('GridCtrl', function ($scope, $http, $resource, testAccountService) {
        $scope.selectedTestAccount = null;

I am loading my scripts like this:

<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/angular.min.js"></script>  
<script src="~/Scripts/angular-resource.min.js"></script>
<script src="~/App/admin/services/Data.js"></script>
<script src="~/App/admin/controllers/GridCtrl.js"></script>

When I run this it gives me an error saying:

Error: Unknown provider: $resourceProvider <- $resource
at Error (<anonymous>)
at http://127.0.0.1:81/Scripts/angular.js:2682:15
at Object.getService [as get] (http://127.0.0.1:81/Scripts/angular.js:2810:39)
at http://127.0.0.1:81/Scripts/angular.js:2687:45

Is there something wrong with the way I am doing this. I am confused about how to set up the service but I can't see what's wrong:

$resource is not part of AngularJS Core.

You have to include: angular-resource.js .


From the docs :

To use $resource make sure you have included the angular-resource.js that comes in Angular package. You can also find this file on Google CDN, bower as well as at code.angularjs.org .

In your data.js and GridCtrl.js, you need to remove the [] from the angular.module('adminApp', []) call.

Like so: angular.module('adminApp')

Also, make sure your app.js is loaded first.

您还需要在模块定义angular.module('adminApp',['ngResource'])中包含角度资源模块定义'ngResource'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM