问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

未能实例化应用程序的模块.为什么

发布网友 发布时间:2022-04-22 08:20

我来回答

1个回答

热心网友 时间:2022-06-18 12:19

[angularjs]未能实例化应用程序的模块。为什么呢?
标签: HTML AngularJS JavaScript
发布时间: 2017/4/23 6:24:18

当我尝试加载的 html 页中包含 AngularJS 代码时,我在火狐浏览器开发人员控制台中出现以下错误︰
Error: [$injector:molerr] Failed to instantiate mole bookApp e to:
[$injector:nomod] Mole 'bookApp' is not available! You either misspelled the mole name or forgot to load it. If registering a mole ensure that you specify the dependencies as the second argument.

请注意,有没有输出在火狐浏览器开发人员控制台中单击的按钮时 index.html 因为模块不被实例化。 如何可以解决此错误?
这里是 index.html :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Find Book By ISBN</title>
<script type="text/javascript" src="bookController.js"></script>
</head>
<body ng-app="bookApp">

<div ng-controller="bookController">
<table>
<tr>
<td width=200>
ISBN:<input type="text" ng-model="book.isbn" />
<br>
<button ng-click="findBook()">Find Book</button>
</td>
<td>
ISBN: <span ng-bind="book.isbn"></span>
<br/>
Title: <span ng-bind="book.title"></span>
<br/>
Author: <span ng-bind="book.author"></span>
</td>
</tr>
</table>
</div>

<!-- build:js({app,.tmp}) scripts/main.js -->
<script src="js/lib/angular.js"></script>
<script src="js/lib/angular-resource.js"></script>
<script src="js/lib/angular-ui-router.js"></script>
<script src="js/lib/angular-ui-router-statehelper.js"></script>
<script src="js/lib/angular-animate.js"></script>
<script src="js/lib/angular-cookies.js"></script>
<script src="js/lib/angular-storage.js"></script>
</body>
</html>

这里是 bookController.js ,座落于非常相同的目录 index.html :
// create angular app
var bookApp = angular.mole('bookApp', []);

// create angular controller
bookApp.controller('bookController', ['$scope', '$http', 'context', function($scope, $http,context) {
var bookId = 1;

$scope.findBook = function() {
console.log('test')
$http.get(context + '/api/findbook/' + bookId).then(function(response) {
$scope.book = response.data;
});
};

}]);

在这里是完整的堆栈跟踪从火狐浏览器控制台︰
Error: [$injector:molerr] Failed to instantiate mole bookApp e to:
[$injector:nomod] Mole 'bookApp' is not available! You either misspelled the mole name or forgot to load it. If registering a mole ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.11/$injector/nomod?p0=bookApp
minErr/<@http://localhost:8080/petclinic/js/lib/angular.js:63:12
mole/<@http://localhost:8080/petclinic/js/lib/angular.js:1764:1
ensure@http://localhost:8080/petclinic/js/lib/angular.js:1688:38
mole@http://localhost:8080/petclinic/js/lib/angular.js:1762:1
loadMoles/<@http://localhost:8080/petclinic/js/lib/angular.js:4094:22
forEach@http://localhost:8080/petclinic/js/lib/angular.js:323:11
loadMoles@http://localhost:8080/petclinic/js/lib/angular.js:4078:5
createInjector@http://localhost:8080/petclinic/js/lib/angular.js:4004:11
bootstrap/doBootstrap@http://localhost:8080/petclinic/js/lib/angular.js:1446:20
bootstrap@http://localhost:8080/petclinic/js/lib/angular.js:1467:1
angularInit@http://localhost:8080/petclinic/js/lib/angular.js:1361:5
@http://localhost:8080/petclinic/js/lib/angular.js:26111:5
trigger@http://localhost:8080/petclinic/js/lib/angular.js:2741:7
createEventHandler/eventHandler@http://localhost:8080/petclinic/js/lib/angular.js:3011:9

http://errors.angularjs.org/1.3.11/$injector/molerr?p0=bookApp&p1=%5B%24injector%3Anomod%5D%20Mole%20'bookApp'%20is%20not%20available!%20You%20either%20misspelled%20the%20mole%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20mole%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.3.11%2F%24injector%2Fnomod%3Fp0%3DbookApp%0AminErr%2F%3C%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A63%3A12%0Amole%2F%3C%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A1764%3A1%0Aensure%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A1688%3A38%0Amole%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A1762%3A1%0AloadMoles%2F%3C%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A4094%3A22%0AforEach%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A323%3A11%0AloadMoles%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A4078%3A5%0AcreateInjector%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A4004%3A11%0Abootstrap%2FdoBootstrap%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A1446%3A20%0Abootstrap%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A1467%3A1%0AangularInit%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A1361%3A5%0A%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A26111%3A5%0Atrigger%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A2741%3A7%0AcreateEventHandler%2FeventHandler%40http%3A%2F%2Flocalhost%3A8080%2Fpetclinic%2Fjs%2Flib%2Fangular.js%3A3011%3A9%0A

解决方法 1:
你 bookController.js 文件不被包含,所以你只需要将其链接 <script type="text/javascript" src="bookController.js"></script>后角脚本的所有标记。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Find Book By ISBN</title>
</head>
<body ng-app="bookApp">

<div ng-controller="bookController">
<table>
<tr>
<td width=200>
ISBN:<input type="text" ng-model="book.isbn" />
<br>
<button ng-click="findBook()">Find Book</button>
</td>
<td>
ISBN: <span ng-bind="book.isbn"></span>
<br/>
Title: <span ng-bind="book.title"></span>
<br/>
Author: <span ng-bind="book.author"></span>
</td>
</tr>
</table>
</div>

<script src="js/lib/angular.js"></script>
<script src="js/lib/angular-resource.js"></script>
<script src="js/lib/angular-ui-router.js"></script>
<script src="js/lib/angular-ui-router-statehelper.js"></script>
<script src="js/lib/angular-animate.js"></script>
<script src="js/lib/angular-cookies.js"></script>
<script src="js/lib/angular-storage.js"></script>
<script type="text/javascript" src="bookController.js"></script>
</body>
</html>
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
八月中国最凉快的地方 八月份哪里最凉快,去哪旅游好?美丽的地方 乱字同韵字是什么意思 华硕笔记本电脑触摸板怎么开笔记本电脑触摸板怎么开启和关闭_百度知 ... 陕西职务侵占案立案准则 结婚后我的恋情维系了十年,怎么做到的? 玉米仁子饭产自哪里 中国期货交易所的交易品种有哪些? 历史要怎么读,有啥诀窍 高中历史诀窍 南京依维柯工程车 如何搭建springmvc的环境 15座依维柯空调怎么往档风玻璃吹? javascript 提交加密用户输入的密码,求教程!!! 如何用tomcat6部署项目 b2驾照能开蓝牌15座得依维柯吗,座位已经被拆的就... springmvc注解标签有哪些 请问这个javascript的加密方式是什么? 15座依维柯+上海牌照+怎样买保险 无标签图元可产生注解资料 关于JS加密,这个是什么加密方式?如何进行加密和解密 15坐的依维柯车身长度6.5米这台车需要什么级别驾驶证 JAVA 前端用RSA.js加密 传到后端解密有乱码 t怎么启动MyEclipsea自带的tomca 南京依维柯15座自重多少吨 3d max compass 参数怎么用 js里面我使用encodeURI加密json字符串传递到另一个... 如何实现js代码MD5加密,传到后台C#中再解密 Spring中PetClinic是做什么的? js加密和解密是什么意思啊 意义何在啊 求大神? 我是B2能开多少座的依维客 做水产基围虾怎么养 目前互联网公司的Java web框架是怎样的 15座车型 有哪些? 求一个javaee的项目源代码,用Spring+jpa+mysql搭建的 B2驾照能开17座的依维柯吗?不过依维柯是蓝牌照?... 请教&lt;context:component-scan/&gt;和&lt;mvc:... 15座有什么车 如何搭建spring环境框架 springmvc环境搭建好了怎么访问 交警用的依维柯是什么型号? 15座商务车哪个品牌性价比最好 springmvc怎么集成两个redis springmvc Date类型数据绑定 03年的依维柯柴油车,五十铃发动机,&#39;15座的,很大... 介绍马尔代夫英语作文 如何在java类中和jsp页面取Spring bean对象 什么是MRF A2照能否开15座的大型专用客车 精通Spring的目录