我有档案:
angularjs.js
scripts.js
ngroute.js
index.html现在,我已经配置了以下路由:
var myApp = angular.module("myApp", ['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider
.when("/author/add", {
controller : "AuthorController",
templateUrl : "view2.html"
})
.when("/author/show", {
controller : "AuthorController",
templateUrl : "view1.html"
})
.otherwise("/", redirectTo : "/author/add")
});这是我的index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="angular.js" ></script>
<script type="text/javascript" src="ngroute.js" ></script>
<script type="text/javascript" src="scripts.js" ></script>
</head>
<body data-ng-app="myApp">
<h1>Hello</h1>
<div data-ng-view=""></div>
<div data-ng-controller="AuthorController">
<ul data-ng-repeat="single in authors">
Author {{ single.author }} has written {{ author.book }}
</ul>
</div>
<a href="#/author/add">Add New Author</a>
</body>
</html>但是,当我单击author/add链接时,它不会加载视图。即使上面的routeConfig代码也会导致js脚本的其余部分停止工作。这个街区有个问题,但我搞不懂是什么!
发布于 2014-05-10 07:42:03
otherwise部件中有语法错误。将路由配置更改为:
myApp.config(function($routeProvider){
$routeProvider
.when("/author/add", {
controller : "AuthorController",
templateUrl : "view2.html"
})
.when("/author/show", {
controller : "AuthorController",
templateUrl : "view1.html"
})
.otherwise({redirectTo : "/author/add"})
});https://stackoverflow.com/questions/23578272
复制相似问题