我试图实现一个包含ng-include指令的基本节点表达角应用程序。
这是我的应用程序的结构:
我的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>
它没有用,有什么想法吗?
答案 0 :(得分:2)
为了让Angular接管(并且为了使指令生效),您需要初始化模块:
<head>
...
<script type="text/javascript">
angular.module('MyApp', ['ui.router']);
</script>
</head>