Service built using express, without using a view engine, set the project directory to static:
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/view'));
app.use(express.static(__dirname + '/node_modules'));
The node entry file index.js is in the root directory, and the directory structure is:
/
/index.js
/public
/view
/view/index.html(首页)
/view/sidebar.html(侧边菜单)
/public/js/app.js(首页的js文件)
index.html is introduced as follows:
<script src="angular/angular.min.js"></script>
<script src="angular-route/angular-route.min.js"></script>
<script src="js/app.js"></script>
The index.html directive is as follows:
<my-sidebar></my-sidebar>
app.js is as follows:
var app = angular.module("myBlog", ["ngRoute"]);
app.directive("mySidebar", function () {
return {
restrict: "E",
replace: true,
templateURL: "sidebar.html",
}
})
After testing, it was found that templateURL did not work. How should I write this path, or how to check what the templateURL here is parsed into?
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:
../../view/sidebar.html
Write templateURL as an absolute path
templateURL: '/view/sidebar.html'
Or add the root path of the component html template in the <base> tag