使用express构建的服务,没有使用视图引擎,将项目目录设置为静态:
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/view'));
app.use(express.static(__dirname + '/node_modules'));
node入口文件index.js在根目录下,目录结构为:
/
/index.js
/public
/view
/view/index.html(首页)
/view/sidebar.html(侧边菜单)
/public/js/app.js(首页的js文件)
index.html中引入如下:
<script src="angular/angular.min.js"></script>
<script src="angular-route/angular-route.min.js"></script>
<script src="js/app.js"></script>
index.html指令如下:
<my-sidebar></my-sidebar>
app.js如下:
var app = angular.module("myBlog", ["ngRoute"]);
app.directive("mySidebar", function () {
return {
restrict: "E",
replace: true,
templateURL: "sidebar.html",
}
})
经过测试发现templateURL没有起作用,请问应该如何写这个路径,或者如何查看这里的templateURL到底被解析成了什么样子?
仅有的幸福2017-05-15 17:14:24
It has been solved. There is something wrong with my chrome. The original code is written correctly.
Provides a way to use the ejs view engine:
app.engine('html', require('ejs').__express);
app.set('view engine', 'html');
app.get('/sidebar.html', function (req, res) {
res.render('sidebar.html');
})
滿天的星座2017-05-15 17:14:24
Write templateURL as an absolute path templateURL: '/view/sidebar.html'
Or add the root path of the component html template in the <base> tag