Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: angular.module is not a function at

Tags:

angularjs

This is in app.js:

var angular = angular.module('ngApp', ['ngRoute']);
angular.config(function($routeProvider) {
$routeProvider
    .when('/', {
        templateUrl: '../templates/companies.html',
        controller: 'companies'
    })
    .........
});

This is in companies.js:

angular.module('ngApp').controller('companies', ['$scope', function($scope) {
    .........
}]);

This is in index.html:

<head>
    <title>Basic demo</title>
    <script src="angular.js"></script>
    <script src="angular-route.js"></script>
    <script src="js/app.js" type="text/javascript"></script>
    <script src="js/Controllers/companies.js" type="text/javascript" ></script>
</head>

I keep getting this error:

Uncaught TypeError: angular.module is not a function at companies.js:1

What am I doing wrong?

like image 875
AmazingDayToday Avatar asked Nov 18 '22 22:11

AmazingDayToday


1 Answers

You are trying to use a variable called angular. Think what causes that variable to exist. That is found in the angular.js script which must then be included first.

At the time your angular code runs, angular does not exist yet. This is an error (see your console window of Dev Tools ). Kindly use same version of Angular file and angular-route !

like image 137
Nivethaa Avatar answered Nov 26 '22 09:11

Nivethaa