admin管理员组

文章数量:1401664

I'm new to AngularJS. Although it is a simple problem, I have found similar error but cause was different.

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.

I have index.html file:

<html ng-app="myApp">
<head>
    <title>Module example</title>
    <script src=".4.4/angular.js"></script>
    <script src=".4.4/angular-route.js"></script>
    <script src="app.js" type="text/javascript"/>
</head>
<body>
    2 + 2 = {{2 + 2}}
</body>

my app.js file is:

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

All files were loaded:

Could you help me guys to resolve this simple issue.

I'm new to AngularJS. Although it is a simple problem, I have found similar error but cause was different.

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.

I have index.html file:

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

my app.js file is:

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

All files were loaded:

Could you help me guys to resolve this simple issue.

Share Improve this question asked Jan 11, 2016 at 19:30 migAlexmigAlex 3733 silver badges16 bronze badges 1
  • 2 try <script src="app.js" type="text/javascript"><script/> instead of <script src="app.js" type="text/javascript"/> – Julien Roy Commented Jan 11, 2016 at 19:32
Add a ment  | 

3 Answers 3

Reset to default 6

Change

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

to:

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

your tag script is not closed right, it must be:

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

Guy, you have forgotten to close your script tag ! And your html tag ! And your doctype !

Try :

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title>Module example</title>
    <script src="https://ajax.googleapis./ajax/libs/angularjs/1.4.4/angular.js"></script>
    <script src="https://ajax.googleapis./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>

And it will works ...

Take a look at https://validator.w3 before asking here, please.

本文标签: javascriptAngularJS module 39myApp39 is not availableStack Overflow