Reputation:
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:
Upvotes: 5
Views: 21295
Reputation: 81
you would also need to include angular resource module definition 'ngResource' on your module defintion angular.module('adminApp', ['ngResource'])
Upvotes: 8
Reputation: 219930
$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 theangular-resource.js
that comes in Angular package. You can also find this file on Google CDN, bower as well as at code.angularjs.org.
Upvotes: 31
Reputation: 4167
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.
Upvotes: 16