AngularJS错误:模块'ngResource'不可用!您要么拼错了模块名称,要么忘记加载它
AngularJS Error :Module 'ngResource' is not available! You either misspelled the module name or forgot to load it
我正在尝试从angular js进行服务调用。我下载了棱角分明的种子项目。并且在view1.js
内部编写了以下代码来调用服务:
'use strict';
angular.module('myApp.view1', ['ngRoute','ngResource'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])
.factory('Entry', ['$resource',function($resource) {
return $resource('http://localhost:8000/emp/'); // Note the full endpoint address
}])
.controller('View1Ctrl', ['Entry',function(Entry) {
var entries = Entry.query(function() {
console.log(entries);
});
}]);
这是index.html
,我在其中包含了所需的脚本:
<!DOCTYPE html>
<!--[if lt IE 7]> <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="myApp" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My AngularJS App</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/normalize.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/main.css">
<link rel="stylesheet" href="app.css">
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
</head>
<body>
<ul class="menu">
<li><a href="#/view1">view1</a></li>
<li><a href="#/view2">view2</a></li>
</ul>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div ng-view></div>
<div>Angular seed app: v<span app-version></span></div>
<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
-->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="angular-resource.js"></script>
<script src="app.js"></script>
<script src="view1/view1.js"></script>
<script src="view2/view2.js"></script>
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>
<script src="components/version/interpolate-filter.js"></script>
</body>
</html>
但在运行该应用程序时,它在浏览器控制台中显示以下错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module myApp.view1 due to:
Error: [$injector:modulerr] Failed to instantiate module ngResource due to:
Error: [$injector:nomod] Module 'ngResource' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
<script src="angular-resource.js"></script>
应该是:
<script src="bower_components/angular-resource/angular-resource.js"></script>
唯一有意义的是angular-resource.js文件没有正确加载,你能看看网络选项卡,看看实际加载了什么文件,模块的名称是什么吗?以确保输入正确。
(很抱歉没有评论,还没有足够的代表)。
您缺少依赖项列表。
如果你传递一个数组作为要注入的依赖项,你需要告诉angular。
['Entry', function (Entry) { }];
应该做到这一点,或者只做function (Entry) { }
。
Entry
未定义的原因是angular不知道需要注入什么u(您将数组符号传递给angular的DI系统)
ps:sry用于糟糕的英语
相关文章:
- reducers在redux中得到Function not Object,what'it’他错了
- 正在尝试为Docpad网站设置Lunr全文搜索插件.我做错了什么
- 谷歌关闭注释赢得'Don’不要告诉我;I’我错了
- Javascript对象/原型.我的理解错了吗
- 什么'这个随机数猜谜游戏错了
- 重新加载重复数据失败,我做错了什么
- 什么'这个谷歌脚本错了
- 柴如承诺即使错了也会过去
- 什么'Gulp错了
- 我做错了什么
- angular mongodb数组格式写错了
- JavaScript排序算法不起作用 - 任何明显的我做错了
- Google Apps 脚本为 getLastRow 抛出电子邮件失败通知,我做错了什么
- Javascript语法 - 我做错了什么
- 角度灯箱不起作用.我做错了什么
- 在这个猫鼬独特的保存前验证中,我做错了什么
- fullcalendar赢得't让我调整事件大小(光标不显示,我做错了)
- document.getElementById为空..什么'I’我的代码错了.
- AngularJS错误:模块'ngResource'不可用!您要么拼错了模块名称,要么忘记加载它
- JS揭示模块模式,我做错了什么