在angularJS中,实例化主模块时遇到问题
每次尝试注入依赖项时,都会出现以下错误: 未捕获错误:[$injector:modulerr]未能实例化模块marbleApp,原因是: 错误:[$injector:modulerr]未能实例化模块路由,原因是: 错误:[$injector:nomod]模块“ngRoute”不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数 我从这里开始,我的代码运行良好:在angularJS中,实例化主模块时遇到问题,angularjs,dependency-injection,Angularjs,Dependency Injection,每次尝试注入依赖项时,都会出现以下错误: 未捕获错误:[$injector:modulerr]未能实例化模块marbleApp,原因是: 错误:[$injector:modulerr]未能实例化模块路由,原因是: 错误:[$injector:nomod]模块“ngRoute”不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数 我从这里开始,我的代码运行良好: var app = angular.module("marbleApp", []); 但是当我尝试
var app = angular.module("marbleApp", []);
但是当我尝试注入这样的依赖项时,我得到了上面的错误
var app = angular.module("marbleApp", ["ngRoute"]);
关于为什么会发生这种情况有什么想法吗?首先,您安装了angular route吗
$ bower install angular-route
如果您也想更新您的bower.json:
$ bower install angular-route --save
此外,正如@ddepablo的评论所建议的,请仔细检查是否已将其添加到index.html
文件中:
<script src="angular-route.js">
(请参阅)记住,当您想要注入一些依赖项时,必须检查两件事: 第一:
var myModule = angular.module('myModule', [
'myDependency',
'mySecondDependency'
]);
第二:
myModule.config(['myDependency', 'mySecondDependency',
function(myDependency, mySecondDependency) {
//here you can use injected stuff
}
]);
干杯 你在HTML中包含了
angular route.js
吗?哇,太蠢了!谢谢,这就解决了!