简体   繁体   中英

Angular ngResource still not recognising $resource

My app has this line at the top, like most angular apps. I assume here it's pulling in ngRoute and ngResource

var myApp = angular.module('myApp', ['ngRoute', 'ui.bootstrap', 'ngResource']);

how ever I create a service below:

myApp.factory('NewsService', function($resource) {
    return $resource('/api/news/:id', {id: '@id'}, {update: {method: 'PUT'}})
})

and in my console I get this message:

Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- NewsService

In my angular folder I have all the js files associated with angular, from angular-animate.js through to angular-touch.js including obviously angular-resource.js , I'm wondering why it is complaining, or what I can do to narrow down to the specific error.

I'm not using the min files at the moment because the errors aren't verbose enough.

In my controllers I just do this:

function newsCreateController($scope, NewsService) {}

You need to make sure you include the appropriate angular files, and application files in your index.html, eg:

<!-- angular related files -->
<script src="/lib/angular/angular.js"></script>
<script src="/lib/angular-resource/angular-resource.js"></script>

<!-- application related files -->
<script src="/apps/myapp/services/newsservice.js"></script>
<script src="/apps/myapp/app.js"></script>

Obviously this is an example, and depends on your file structure.

Once everything is included, you need to make sure your modules are setup correctly, and injected accordingly.

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