angular module is not available
-
20-12-2019 - |
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?
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
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow