我尝试使用ui-router创建一个角度应用程序。
在HTML文件中,我在body元素中有这个:
<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>
在模块中,我有这个:
angular.module('ang', ['ui-router'])
但是Chrome给了我这个错误:
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)
我该如何解决这个问题?
答案 0 :(得分:4)
当您使用ng-app="ang"
将模块定义为
angular.module('ang', ['ui-router'])
而不是
angular.module('app', ['ui-router'])
更改这些文件的顺序,因为angular.js
angular-ui-router.min.js
<script src="Dependencies/angular.js"></script>
<script src="Dependencies/angular-ui-router.min.js"></script>
答案 1 :(得分:3)
您需要在angular-ui-router.min.js
文件
angular.js
文件
<script src="Dependencies/angular.js"></script>
<script src="Dependencies/angular-ui-router.min.js"></script>
定义依赖项ui.router
而不是ui-router
。
angular.module('ang', ['ui.router']);
这是DEMO
答案 2 :(得分:3)
您的角度脚本引用应出现在angular-ui-router脚本引用之前。
<script src="Dependencies/angular.js"></script>
<script src="Dependencies/angular-ui-router.min.js"></script>