如何在Angular的ejs文件中正确引用js文件 [英] how to correctly reference a js file in a ejs file in Angular
本文介绍了如何在Angular的ejs文件中正确引用js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的项目结构:
公共-js--angular.min.js--angularApp.js范本-意见--index.ejs
public -js --angular.min.js --angularApp.js templates -views --index.ejs
这是我的index.ejs文件:
This is my index.ejs file:
<html>
<head>
<title>My Angular app!</title>
<script type='text/javascript' src="../../public/js/angular.min.js"></script>
</head>
<body ng-app="flapperNews" ng-controller="MainCtrl">
<div>
{{test}}
</div>
<script type='text/javascript' src="../../public/js/angularApp.js"></script>
</body>
</html>
运行此命令时,js文件上出现404 not found错误.
When I run this I get a 404 not found error on the js files.
我尝试将其添加到路由文件夹中的middleware.js中:
I tried adding this to middleware.js in the routes folder:
app.use("/public/js/angularApp.js", express.static(__dirname + '/public/js/angularApp.js'));
但这没用,我也尝试使用此路径:
But this didnt work, I also tried using this path:
/public/js/
但是也没有用.
如何在ejs文件中正确引用Javascript文件?
How can I correctly reference a Javascript file in a ejs file?
推荐答案
从访问者角度来看,公用文件夹是您的根目录.所以您的情况应该是
The public folder is you root directory from the vistor perspective. So in your case it should be
<script type='text/javascript' src="/js/angular.min.js">
这篇关于如何在Angular的ejs文件中正确引用js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文