简体   繁体   English

Angular仍然无法识别$ resource

[英]Angular is still not recognising $resource

I am injecting ngResource in my app's module : 我在应用程序的模块中注入ngResource:

angular.module('confusionApp', ['ui.router', 'ngResource'])

, then injecting $resource dependency in my service : ,然后在我的服务中注入$ resource依赖项:

angular.module('confusionApp')
    .constant('baseURL', 'http://localhost:3000/')
    .service('menuFactory', ['$resource', 'baseURL', function($resource, baseURL) {

I have also included the script in my index.html file : 我还在index.html文件中包含了脚本:

<script src="../bower_components/angular/angular.js"></script>
    <script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="../bower_components/angular-resource/angular-resource.js"></script>
    <script src="scripts/app.js"></script>
    <script src="scripts/controllers.js"></script>
    <script src="scripts/services.js"></script>

I am running a json-server on my machine and whenever the $resource is requesting data, the browser's js console cannot identify $resource and shows this error: 我在机器上运行一个json服务器,并且每当$ resource请求数据时,浏览器的js控制台都无法识别$ resource并显示此错误:

Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- menuFactory 错误:[$ injector:unpr]未知提供程序:$ resourceProvider <-$ resource <-menuFactory

Please help or do point towards somewhere which can help!! 请帮助或指向可以帮助的地方!!

Update 更新资料

my bower.json dependencies: 我的bower.json依赖项:

"dependencies": {
"bootstrap": "~3.3.5",
"font-awesome": "~4.4.0",
"angular": "1.4.x",
"angular-route": "1.4.x",
"angular-resource": "1.4.x",
"angular-ui-router": "~0.2.17"
}

It turns out to be a conflict between versions of angular and angular-resource. 事实证明,这是角度和角度资源版本之间的冲突。 I don't know how it got installed, given I had installed it through bower, although I did explicitly mentioned it's version in bower.json, did not let the bower command tool save it while installing. 我不知道它是如何安装的,因为我已经通过bower安装了它,尽管我确实在bower.json中明确提到了它的版本,但是在安装时并没有让bower命令工具保存它。 I had to remove the angular-resource from the bower_components and also removed the dependency from bower.json and reinstall angular-resource with the -S flag. 我必须从bower_components中删除angular-resource,还必须从bower.json中删除依赖项,并使用-S标志重新安装angular-resource。

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

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