简体   繁体   中英

Angular - Module not found

I have tried to create an angular application using ui-router.

In HTML file I have this in the body element:

<div class="container" ng-app="ang">
    <header ng-include="'templates/head.html'"></header>

    <div ui-view></div>

    <footer ng-include="'templates/foot.html'"></footer>
</div>

<script src="Dependencies/jquery-1.11.3.min.js"></script>
<script src="Dependencies/angular-ui-router.min.js"></script>
<script src="Dependencies/angular.js"></script>
<script src="js/ang.js"></script>

In the module, I have this:

angular.module('ang', ['ui-router'])

But Chrome gives me out this error:

Uncaught TypeError: Cannot read property 'isDefined' of undefined(anonymous function) @ angular-ui-router.min.js:7(anonymous function) @ angular-ui-router.min.js:7
angular.js:80 Uncaught Error: [$injector:modulerr] Failed to instantiate module ang due to:
Error: [$injector:nomod] Module 'ang' 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.
http://errors.angularjs.org/1.3.0/$injector/nomod?p0=ang
    at REGEX_STRING_REGEXP (file:///home/user/Desktop/ang/Dependencies/angular.js:80:12)
    at file:///home/user/Desktop/ang/Dependencies/angular.js:1797:17
    at ensure (file:///home/user/Desktop/ang/Dependencies/angular.js:1721:38)
    at module (file:///home/user/Desktop/ang/Dependencies/angular.js:1795:14)
    at file:///home/user/Desktop/ang/Dependencies/angular.js:4064:22
    at forEach (file:///home/user/Desktop/ang/Dependencies/angular.js:335:20)
    at loadModules (file:///home/user/Desktop/ang/Dependencies/angular.js:4048:5)
    at createInjector (file:///home/user/Desktop/ang/Dependencies/angular.js:3974:11)
    at doBootstrap (file:///home/user/Desktop/ang/Dependencies/angular.js:1484:20)
    at bootstrap (file:///home/user/Desktop/ang/Dependencies/angular.js:1505:12)
http://errors.angularjs.org/1.3.0/$injector/modulerr?p0=ang&p1=Error%3A%20%…F%2F%2Fhome%2Fuser%2FDesktop%2Fang%2FDependencies%2Fangular.js%3A1505%3A12)

How can I fix this?

As you are using ng-app="ang" define module as

angular.module('ang', ['ui-router'])

instead of

angular.module('app', ['ui-router'])

Change the sequence of these files as angular.js should be loaded before angular-ui-router.min.js

<script src="Dependencies/angular.js"></script>
<script src="Dependencies/angular-ui-router.min.js"></script>

You need to add the angular-ui-router.min.js file after the angular.js file,

<script src="Dependencies/angular.js"></script>
<script src="Dependencies/angular-ui-router.min.js"></script>

And define the dependency like ui.router not the ui-router .

angular.module('ang', ['ui.router']);

here is the DEMO

您的角度脚本引用应出现在angular-ui-router脚本引用之前。

<script src="Dependencies/angular.js"></script> <script src="Dependencies/angular-ui-router.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM