我一直在尝试在我的项目中实现路由,但发现很难这样做。这是我的index.html代码
<!DOCTYPE html>
<!-- Angular Material CSS now available via Google CDN; version 0.11.2 used here -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/0.11.2/angular-material.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-route.min.js"></script>
<!--<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>-->
<!-- Angular Material Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>
<script type="text/javascript" src="./app/app.js"></script>
<section ng-controller="MainCtrl">
<div ng-view></div>
</section>
<!-- Angular Material Javascript now available via Google CDN; version 0.11.2 used here -->
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.11.2/angular-material.min.js"></script>
这是我的app.js文件:
(function(){
"use strict";
var app = angular.module('math_teacher', ['ngMaterial']);
app.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/welcome',{
templateUrl: 'welcome.html',
controller: 'MainCtrl',
}).
otherwise({redirectTo: '/welcome'});
}]);
app.controller('MainCtrl', ['$scope', function(){
}]);
app.controller('TutorialsController', ['$scope', function(){
}]);
})();
这是我的welcome.html测试我的路线是否正常工作
<h1>Welcome to this page</h1>
<p>This really shows that the route is at work</p>
在我的服务器上运行此操作是我在控制台中看到的内容:
Uncaught TypeError:无法读取未定义的属性'module'(匿名函数)@ angular-route.js:24(匿名函数)@ angular-route.js:6
未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.3.15/ $ injector / modulerr?p0 = math_teacher&amp; p1 = Er ... gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.15%2Fangular.min.js% 3A38%3A135)(匿名函数)@ angular.js:38(匿名函数)@ angular.js:4138r @ angular.js:323g @ angular.js:4099ab @ angular.js:4025d @ angular.js:1452uc @ angular .js:1473Jd @ angular.js:1367(匿名函数)@ angular.js:26304a @ angular.js:2762c @ angular.js:3032
请帮忙
答案 0 :(得分:3)
我找到了解决方案! 添加后 &#39; ngRoute&#39; 依赖它仍然没有工作
我所做的只是在angularjs脚本之后添加我的脚本,而不是在它之前
答案 1 :(得分:1)
您必须在应用中加入'ngRoute'
模块。
var app = angular.module('math_teacher', ['ngMaterial', 'ngRoute']);