简体   繁体   English

Angular ngResource仍然无法识别$ resource

[英]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 我认为这里是ngRoutengResource

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 错误:[$ injector:unpr]未知提供程序:$ 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. 在我的angular文件夹中,我有所有与angular相关的js文件,从angular-animate.jsangular-touch.js包括明显的angular-resource.js ,我想知道为什么会抱怨,或者我该怎么做缩小到特定错误。

I'm not using the min files at the moment because the errors aren't verbose enough. 我目前不使用min文件,因为错误不够详细。

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: 您需要确保在index.html中包括适当的角度文件和应用程序文件,例如:

<!-- 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. 包含所有内容后,您需要确保正确设置了模块并进行了相应注入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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