我正在尝试实现一个基本的 node-express angular 应用程序,其中包含一个 ng-include 指令。
这是我的应用程序的结构:
- 应用程序:
- 服务器.js
- 包.json
- 上市:
- js
- css
- 索引.html
- 部分:
- header.html
- 部分about.html
- 部分homt.html
我的 server.js 的内容如下:
var express = require("express");
var app = express();
var port = process.env.PORT || 8080;
app.configure(function () {
app.use(express.static(__dirname + "/public"));
app.use(express.logger("dev"));
});
app.listen(port);
console.log("App listening on port: " + port);
这是我的 index.html 的内容:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AngularJS UIRouter demo</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="./css/style.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.15/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
</head>
<body ng-app="MyApp">
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<a href="#" class="navbar-brand">DD test Angular-UI Router</a>
</div>
<ul class="nav navbar-nav">
<li><a href="./partials/partial-home.html">Home</a></li>
<li><a href="./partials/partial-about.html">About</a></li>
</ul>
</nav>
<div ui-view></div>
</body>
</html>
但是,当我尝试将 index.html 简化为:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AngularJS UIRouter demo</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="./css/style.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.15/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
</head>
<body ng-app="MyApp">
<div ng-include="'./partials/header.html'" ></div>
<div ui-view></div>
</body>
</html>
使用 header.html 显然包括:
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<a href="#" class="navbar-brand">DD test Angular-UI Router</a>
</div>
<ul class="nav navbar-nav">
<li><a href="./partials/partial-home.html">Home</a></li>
<li><a href="./partials/partial-about.html">About</a></li>
</ul>
</nav>
它不起作用,有什么想法吗?