Question

This is surely a noob question but I just can't seem to figure out what is wrong with this simple module initiation (JSFiddle):

var myApp = angular.module('myApp', []);

I get an error saying that "Module 'myApp' is not available!". Does anyone know why this does not work?

Was it helpful?

Solution

It's because (in the fiddle at least) that the script is run on window.onload, thus angular cannot find the module before it sees in the DOM that there should be a module named myApp.

before it was (in the head):

window.onload = function() {
    angular.module(...)
}

but it had to be:

angular.module(...)

ie. not waiting until the document was fully loaded, thus creating the module before angular sees that it should bootstrap the module myApp.

updated fiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top