只需尝试以下代码并获取错误
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Routing Intro</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
<script scr="example.js"></script>
</head>
<body ng-app="mainApp">
<div ng-view></div>
</body>
</html>
这是我的example.js文件
var application = angular.module ('mainApp', ['ngRoute']);
application.config (function ($routeProvider){
$routeProvider
.when('/', {
template : 'Welcome User!'
})
.when('/anotherPage',{
tempalte : 'Welcome to Another page'
})
otherwise ({
redirectTo : '/'
});
});
我收到以下错误 angular.js:4458未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.8/ $ injector / modulerr?p0 = mainApp&amp; p1 =错误%3A ... ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular。 min.js%3A19%3A463)
答案 0 :(得分:1)
角度路由器不是核心角度模块的一部分。您需要包含它的javascript文件:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.min.js"></script>