2016-01-11 3 views
-1

Я новичок в AngularJS. Хотя это простая проблема, я нашел аналогичную ошибку, но причина была другая.Модуль AngularJS 'myApp' недоступен

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.

У меня есть файл index.html:

<html ng-app="myApp"> 
<head> 
    <title>Module example</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.js"></script> 
    <script src="app.js" type="text/javascript"/> 
</head> 
<body> 
    2 + 2 = {{2 + 2}} 
</body> 

мой app.js файл является:

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

Все файлы были загружены: enter image description here

Не могли бы вы помочь мне решить эту проблему.

+2

try

5

тег сценария не закрыта правильно, оно должно быть:

<script src="app.js" type="text/javascript"></script> 
2

Гай, вы забыли закрыть тег сценария ! И ваш тег html! И ваш doctype!

Try:

<!DOCTYPE html> 
<html ng-app="myApp"> 
<head> 
    <title>Module example</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.js"></script> 
    <script src="app.js" type="text/javascript"></script> 
</head> 
<body> 
    2 + 2 = {{2 + 2}} 
</body> 
</html> 

И это работает ...

Взгляните на https://validator.w3.org, прежде чем спрашивать здесь, пожалуйста.

Смежные вопросы