在我的应用中使用Angular.js时出现以下错误。
错误:
angular.js:38Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.6/$injector/modulerr?p0=app&p1=Error%3A%20%…oudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.4.6%2Fangular.min.js%3A41%3A35)
我在下面提供我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="app">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DEMO</title>
<link href="bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-route.js"></script>
<script src="angularuirouter.js" type="text/javascript"></script>
</head>
<body>
<a href="#/visitplace">I want to go for a trip</a>
<div ng-view></div>
<script src="script.js"></script>
</body>
</html>
script.js:
"use strict";
var app = angular.module( "app",[],function( $routeProvider ) {
$routeProvider.when( "/visitplace", {
templateUrl: "placetovisit.html",
controller: "TourCoordinatorCtrl",
resolve: {
"accommodation": function( $q, $timeout ) {
var myFriend = $q.defer();
$timeout(function(){
myFriend.resolve({
hotelName: function( ) {
return "My Friend's friend's hotel";
},
roomNo: function( ) {
return "404";
}
});
},5000);
return myFriend.promise;
}
}
});
} );
app.controller( "TourCoordinatorCtrl", function( $scope, accommodation ) {
$scope.name = "Shidhin";
$scope.place = "Switzerland";
$scope.hotel = accommodation.hotelName( );
$scope.roomno = accommodation.roomNo( );
} );
我该如何解决此错误?
您必须这样定义您的应用程序(例如):
var app = angular.module( "app", ['ngRoute']);
然后配置路由提供者。
angular.module('app', ['ngRoute'])