When I use jsfiddle to learn Angular, I got an error like blow:
Uncaught Error: [$injector:modulerr] Failed to instantiate module MyApp due to:
Error: [$injector:nomod] Module 'MyApp' 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.
Thanks @Khanh TO's answer, I solved this problem.
But I don't understand why I can't put code in dom ready event.
So the same error occurs like this:
<!DOCTYPE html>
<html lang="en" ng-app="MyApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script>
document.addEventListener('DOMContentLoaded',function() {
var app = angular.module('MyApp',[]);
}, false);
</script>
</head>
<body>
<div>
Hello {{val}}
</div>
</body>
</html>
So I have 2 questions
1: How should I understand that Angular begins compiling the DOM when the DOM is fully loaded.
2: Since Angular begins compiling the DOM when the DOM is fully loaded, the above code should run correctly, but why an error occurred.
Thanks in advance for your help.