Cannot read property 'module' of undefined

All we need is an easy explanation of the problem, so here it is.

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.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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)

Method 2

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>

Method 3

<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

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply