Inactivity error: [$ injector: modulerr] Failed to create module error in Angular.js App on Apache

I am using Apache server to host angular application. This is index.html:

<html> <head> <script src="/lib/angular/angular.js"> </head> <script> myapp = angular.module('myapp', []); myapp.controller('indexCtrl', function($scope){ $scope.words = ['It','is','what','it','is'] }); </script> <body ng-app="myapp"> <div ng-controller="indexCtrl"> <div ng-repeat="word in words"> {{word}} </div> </div> </body> </html> 

When I hit the html from the browser, it shows a blank page with this error:

Unprepared error: [$ injector: modulerr] Unable to create myapp module because of: Error: [$ injector: nomod] 'myapp' module is not available!

You either mistakenly wrote the name of the module, or forgot to load it. If registering a module ensures that you specify the dependencies as the second argument.

What could be wrong?

+8
angularjs angularjs-ng-repeat
source share
3 answers

The error is related to duplicate values ​​inside the array. I added track by $index inside ng-repeat to solve this problem.

DOCS : ng-repeat

Modified Code :

 <html> <head> <script src="/lib/angular/angular.js"></script> </head> <script> var myapp = angular.module('myapp', []); myapp.controller('indexCtrl', function($scope){ $scope.words = ['It','is','what','it','is'] }); </script> <body ng-app="myapp"> <div ng-controller="indexCtrl"> <div ng-repeat="word in words track by $index"> {{word}} </div> </div> </body> </html> 
+9
source share

Please turn on the corners in the body.

 <script src="/lib/angular/angular.js"> 

Include this line in the body. Hope it works!

+1
source share

Place the <script> and the end of the body:

 <body ng-app="myapp"> <div ng-controller="indexCtrl"> <div ng-repeat="word in words"> {{word}} </div> </div> <script> myapp = angular.module('myapp', []); myapp.controller('indexCtrl', function($scope){ $scope.words = ['It','is','what','it','is'] }); </script> </body> 

which is a good practice in HTML, and especially in Angular, to put the definition of your JS file just before the body ends

0
source share

All Articles