我对AngularJS相对较新,并且得到了一个“Uncaught Error:[$ injector:modulerr]”。另外,我在各种js文件的第一行得到了几个语法错误。
我似乎无法纠正这种情况,有什么想法吗?
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User CRM</title>
<!-- FOR ANGULAR ROUTING -->
<base href="/">
<!-- CSS -->
<!-- load bootstrap from CDN and custom CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.4.0/animate.min.css">
<link rel="stylesheet" href="public/assets/css/style.css">
<!-- JS -->
<!-- load angular and angular-route via CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-route.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-animate.js"></script>
<!-- controllers -->
<script src="public/app/controllers/mainCtrl.js"></script>
<script src="public/app/controllers/userCtrl.js"></script>
<!-- services -->
<script src="public/app/services/authService.js"></script>
<script src="public/app/services/userService.js"></script>
<!-- main Angular app files -->
<script src="public/app/app.js"></script>
<script src="public/app/app.routes.js"></script>
</head>
<body ng-app="userApp" ng-controller="mainController as main">
<!-- NAVBAR -->
<header>
<div class = "navbar navbar-inverse" ng-if="main.loggedIn">
<div class="container">
<div class="navbar-header">
<a href="/" class="navbar-brand"><span class="glyphicon glyphicon-fire text-danger"></span> User CRM</a>
</div>
<ul class="nav navbar-nav">
<li><a href="/users"><span class="glyphicon glyphicon-user"></span> Users</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li ng-if="!main.loggedIn"><a href="/login">Login</a></li>
<li ng-if="main.loggedIn" class="navbar-text">Hello {{ main.user.name }}!</li>
<li ng-if="main.loggedIn"><a href="#" ng-click="main.doLogout()">Logout</a></li>
</ul>
</div>
</div>
</header>
<main class="container">
<!-- ANGULAR VIEWS -->
<div ng-view></div>
</main>
</body>
</html>
app.js
angular.module('userApp', [
'ngAnimate', // add animations to our Angular Directives
'app.routes', // routing for our application
'authService', // service file
'mainCtrl', // main view controller
'userCtrl', // controller for user management pages
'userService' //service file
]);
app.routes.js
angular.module('app.routes', ['ngRoute'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
// home page route
.when('/', {
templateUrl: 'app/views/pages/home.html'
})
// login page
.when('/login', {
templateUrl: 'app/views/pages/login.html',
controller: 'mainController',
controllerAs: 'login'
})
// get rid of the hash in the URL
$locationProvider.html5Mode(true);
});
答案 0 :(得分:0)
尝试使用angular-animate模块的更新版本。
如果您通过CDN加载脚本,AngularJS documentation for v1.4.8会提示一些选项。例如,试试这个:https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.js
答案 1 :(得分:0)
我加载了angular.js模块而不是缩小版本以获取更详细的错误消息,并获得未定义userApp的错误通知。事实证明,在其他依赖关系中没有正确定义的问题。所以,我删除了所有依赖项,但删除了ngAnimate和app.routes,并从index.html文件中删除了ng-controller“mainController as main”。这似乎解决了这个问题,但是,现在我需要在mainCtrl.js文件中找到我的错误,这样我才能使用mainController。
感谢您的帮助!