我试图建立一个简单的登录"应用程序是为了在AngularJS中开始,我正在遵循这方面的指南。它提到我应该添加" ngRoute"作为我的应用程序的依赖,我已经完成了,我也在我的代码中包含了angular-route.js文件的CDN,但无论我尝试什么,我都收到以下错误:
angular.js:38Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.6.1/$injector/modulerr?p0=loginApp&p1=Referen…googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.1%2Fangular.min.js%3A20%3A1)
at angular.js:38
at angular.js:4759
at q (angular.js:357)
at g (angular.js:4720)
at eb (angular.js:4642)
at c (angular.js:1838)
at Mc (angular.js:1859)
at pe (angular.js:1744)
at angular.js:32977
at HTMLDocument.b (angular.js:3314)
这是我的index.html:
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta charset="utf-8" />
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-route.js" type="text/javascript"></script>
<script src="script/app.js" type="text/javascript"></script>
<script src="script/controllers/controllers.js" type="text/javascript"></script>
<script src="script/service/services.js" type="text/javascript"></script>
<div ng-app="loginApp">
<div ng-view></div>
<script type="text/ng-template" id="loginView.html">
<div>
<input type="text" ng-model="username" /><br />
<input type="password" ng-model="password" /><br />
<input type="button" value="Submit" ng-click="submitCredentials()" /><br />
</div>
</script>
<script type="text/ng-template" id="successView.html">
<div>
<p>
Success! You logged in!
</p>
</div>
</script>
</div>
</body>
</html>
这是我的app.js:
"use strict";
angular.module("loginApp", ['ngRoute'])
.run(function($state, LoginService) {
if(!LoginService.isAuthenticated()) {
$state.transitionTo('login');
}
})
.config(['$routeProvider', function ($routeProvider) {
$urlRouterProvider.otherwise('/success');
$routeProvider.
when('/login', {
templateUrl: 'loginView.html',
controller: 'loginCtrl'
}).
when('/success', {
templateUrl: 'successView.html',
controller: 'successCtrl'
}).
otherwise({
redirectTo: '/login'
});
}]);
我相信所有相关的代码。如果需要更多信息,请随时提出要求。
编辑1
抱歉,我忘了删除urlRouterProvider和状态。它现在工作正常。谢谢大家。