我有一个简单的AngularJS应用程序。当我运行我的应用时,它不会显示应该在<ng-view>
标记中加载的部分视图。
这是我的index.html
:
<!DOCTYPE html>
<html ng-app="TestApp">
<head>
<title>Test!</title>
</head>
<body>
<h2>Index!</h2>
<ng-view></ng-view>
<script src="/Scripts/angular.js"></script>
<script src="/Scripts/angular-route.js"></script>
<script src="/App/app.js"></script>
<script src="/App/controllers/controllers.js"></script>
</body>
</html>
这是我的app.js
:
var app = angular.module('TestApp', ['ngRoute']);
// Routes
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/dashboard', {
controller: 'DashboardController',
templateUrl: '/App/partials/dashboard.html'
})
.otherwise({ reditectTo: '/dashboard' });
}]);
我的controllers.js
:
app.controller("DashboardController", ["$scope", function ($scope) {
$scope.posts = [
{ "title": "asdf", "description": "describe" },
{ "title": "second one", "description": "second describe" },
];
}]);
当我运行我的应用程序时,我只能看到<h2>Index!</h2>
消息。为什么我的Dashboard.html
部分未加载?我没有收到任何错误。