我一直在努力使ng-view工作,但ng-view不显示任何东西。我有angular.js 1.2x和angular-route.js。花了很多时间让它工作,但无法弄清楚。angularjs路由问题:无法使用ng-view获得路由工作
<!DOCTYPE html>
<html ng-app="app">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="angular.js"></script>
<script src="angular-route.js"></script>
<script>
var app = angular.module("app", ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/',
{
templateUrl: "app.html"
})
.when('/pizza', {
templateUrl: "app.html"
}).otherwise({
template: "This doesn't exist!"
})
});
app.controller("AppCtrl", function($scope) {
$scope.model = {
message: "This is my app!!!"
}
});
</script>
</head>
<body>
<div>
<h1>Hello There {{2+2}}</h1>
<div ng-view>
</div>
</div>
</body>
</html>
当我查看页面时,它只显示Hi There 4.这表示页面显示并且表达式{{2 + 2}}正在工作。我确实拥有根目录下的所有html文件。
任何想法的家伙????????? 感谢
没有。控制器不是必需的。 – Sheraz
因为在你不需要他们,或者你还没有尝试? –