Stig Perez
Stig Perez

Reputation: 3813

angular module is not available

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?

Upvotes: 3

Views: 4908

Answers (1)

Björn Roberg
Björn Roberg

Reputation: 2366

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

Upvotes: 1

Related Questions