Tuesday, February 9, 2016

Uncaught Error: [$injector:nomod] Module 'xxxx' is not available!



http://www.johnpapa.net/easy-fix-to-a-common-angular-module-error/

Correct line
angular.module('musicApp',[])


Incorrect line
angular.module('musicApp')

You need to have ",[]" when specify a module

Uncaught Error: [$injector:nomod] Module 'musicApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.9/$injector/nomod?p0=musicApp
angular.js:4470 Uncaught Error: [$injector:modulerr] Failed to instantiate module musicApp due to:
Error: [$injector:nomod] Module 'musicApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.9/$injector/nomod?p0=musicApp


the something in `ng-app="something"` in your html must match the name of your main app module.

I got the same error, but it was because I forgot the angular.module("name", [])
you cant forget the [] or it wont inject and dependencies.


below is the app.js file

angular.module('musicApp',[])
.controller('ArtistController', ['$scope', ArtistController]);
function ArtistController($scope) {
    $scope.artist='Foo'
}

below is the index.html file
<!DOCTYPE html>
<html>
<head>
    <title>test</title>
<meta charset="utf-8" />
    <script src="scripts/angular.js"></script>
    <script src="scripts/app.js"></script>
</head>
<body>
    <div ng-app="musicApp">
    <div ng-controller="ArtistController">
        {{artist}}
    </div>
</div>
</body>

</html>


No comments:

Post a Comment