该项目基于 Express,没有使用视图引擎。我设置了一些静态目录:
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/view'));
app.use(express.static(__dirname + '/node_modules'));
index.js位于webroot中,directoris类似于:
/
/index.js
/public
/view
/view/index.html(index)
/view/sidebar.html
/public/js/app.js(js for index.html)
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>
应用程序.js:
var app = angular.module("myBlog", ["ngRoute"]);
app.directive("mySidebar", function () {
return {
restrict: "E",
replace: true,
templateURL: "sidebar.html",
}
})
该templateURL
工作不正常,我该怎么写,或者我怎么能看到我的凉亭的URL。Tx!
谢谢你看我的问题。我终于发现我的 chrome 不能正常工作,我提供的代码是正确的。在这里,我提供了另一种需要视图引擎的方法:
npm install --save ejs
app.engine('html', require('ejs').__express);
app.set('view engine', 'html');
app.get('/sidebar.html', function (req, res) {
res.render('sidebar.html');
})
该templateURL
发送“GET” HTTP请求,这样我可以写app.get('/sidebar.html')
接收到请求,并呈现HTML。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句