Javascript 无法读取未定义的属性“模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27462602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot read property 'module' of undefined
提问by Sumit Gera
I have a basic understanding of Djangoand JSand recently I started learning Angular.js. I wrote code for showing hardcoded jsonusing Angularand failed. I got the following error:
我有一个基本的了解Django和JS最近我开始学习Angular.js。我编写了用于显示硬编码jsonusing 的代码Angular,但失败了。我收到以下错误:
Uncaught TypeError: Cannot read property 'module' of undefined at line 10 of django-angular.js
I went through the file and saw this line:
我浏览了文件,看到了这一行:
var djng_forms_module = angular.module('ng.django.forms', []);
I don't know what the error means by undefined. I went through some of the links having similar problems but with no success.
我不知道未定义的错误是什么意思。我浏览了一些有类似问题的链接,但没有成功。
回答by Gregor Petrin
Have you forgotten to load AngularJS before your script? The error means that the object angularhasn't been seen by Javascript yet and therefore modulecannot be called on it.
您是否忘记在脚本之前加载 AngularJS?该错误意味着该对象angular尚未被 Javascript 看到,因此module无法对其调用。
(that's actually a simplification but it should illustrate what's going on)
(这实际上是一种简化,但它应该说明发生了什么)
回答by Tomek Kozlowski
order matters here
订单在这里很重要
<script src="javascripts/lib/angular.min.js" type="text/javascript"></script>
<script src="javascripts/lib/angular-route.min.js" type="text/javascript"></script>
回答by Steven Wong
<script type="text/javascript" src="angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-cookies.js"></script>
<script type="text/javascript" src="angular-route.js"></script>
you have to put angular.min.js before angular-route.js and angular-cookies.js
你必须把 angular.min.js 放在 angular-route.js 和 angular-cookies.js 之前

