16

I have a basic understanding of Django and JS and recently I started learning Angular.js. I wrote code for showing hardcoded json using Angular and failed. I got the following error:

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.

3 Answers 3

34

Have you forgotten to load AngularJS before your script? The error means that the object angular hasn't been seen by Javascript yet and therefore module cannot be called on it.

(that's actually a simplification but it should illustrate what's going on)

Sign up to request clarification or add additional context in comments.

5 Comments

Yes. I have included <script type="text/javascript" src="{% static "djangular/js/django-angular.js" %}"></script> before my js code.
Sure, but have you included angular.js (or angular.min.js) as well?
No. But when I included, I got an error which I tried to solve by adding separate module for ngRoute. I have included following files: jquery.min.js, angular.min.js, angular.route.js, django-angular.js and script.js.
What about the error you started this question for, Cannot read property 'module' of undefined? Is the order of included scripts OK (are they included in the same order in which you wrote them in your comment)?
This error has been resolved. Thanks. But I am still stuck at another error.
9

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>

Comments

4
<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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.