我正在尝试使用ui-router设置角度app我有一个问题angular没有注册模块computerTrading
。我在下面粘贴了错误。
app.js
angular.module('computerTrading', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider){
'use strict';
// $urlRouterProvider.otherwise(function($injector){
// var $state = $injector.get('$state');
// $state.go('home');
// });
$urlRouterProvider.otherwise('home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'views/home.html',
controller: 'MainController'
})
.state('nerd', {
url: '/nerd',
templateUrl: 'views/nerd.html',
controller: 'NerdController'
});
});
index.html
<body ng-app="computerTrading">
<div class="container-fluid">
<!-- HEADER -->
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" ui-sref="home">Stencil: Node and Angular</a>
</div>
<!-- LINK TO OUR PAGES. ANGULAR HANDLES THE ROUTING HERE -->
<ul class="nav navbar-nav">
<li><a ui-sref="nerd">Nerds</a></li>
</ul>
</nav>
<!-- ANGULAR DYNAMIC CONTENT -->
<div ui-view></div>
</div>
<script src="libs/angular/angular.min.js"></script>
<script src="libs/angular-ui-router/release/angular-ui-router.min.js"></script>
<!-- ANGULAR CUSTOM -->
<script src="js/controllers/MainCtrl.js"></script>
<script src="js/controllers/NerdCtrl.js"></script>
<script src="js/services/NerdService.js"></script>
<script src="js/appRoutes.js"></script>
<script src="js/app.js"></script>
</body>
错误
Uncaught Error: [$injector:nomod] http://errors.angularjs.org/1.6.1/$injector/nomod?p0=computerTrading
at angular.js:38
at angular.js:2183
at b (angular.js:2107)
at Object.module (angular.js:2181)
at MainCtrl.js:1
答案 0 :(得分:3)
computerTrading
在app.js
中定义为angular.module('computerTrading', ['ui.router'])
。
考虑到在其他文件中调用angular.module('computerTrading')
getter函数,它们无法获得尚不存在的模块。
app.js
最后加载到<!-- ANGULAR CUSTOM -->
部分,应该先加载到那里。