我正在理解路由,我有一个简单的应用程序,在标题区域的顶部有几个按钮。按钮运行良好并显示正确的信息,但我已指示其中一个页面(directory.html)使用" myController"我创建的控制器,但它继续给我curley括号而不是实际的范围数据。有人能告诉我我做错了吗?
HTML
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<title>Sample app</title>
<link href="content/css/styles.css" rel="stylesheet" type="text/css" />
<script src="app/lib/angular.min.js"></script>
<script src="app/lib/angular-route.min.js"></script>
<script src="app/app.js"></script>
</head>
<body>
<header ng-include="'header.html'"></header>
<main ng-view></main>
</body>
</html>
JS
angular.module('myApp', ['ngRoute'])
.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/home', {
templateUrl: 'views/home.html'
})
.when('/directory', {
templateUrl: 'views/directory.html',
//since this page requires a controller
controller: 'myController'
})
.otherwise({
redirectTo: '/home'
});
}]);
angular.module('myApp', [])
.controller('myController', function($scope) {
$scope.message = ("Hello World");
});
Directory.html
<p>This is my directory page.</p>
<p>{{message}}</p>
header.html中
<div id="menu-bar">
<h1>My Sample App</h1>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#directory">Directory</a></li>
</ul>
</div>
答案 0 :(得分:1)
您的js文件无效。
{{1}}
您已将控制器放在配置模块中......