【问题标题】:how to correctly reference a js file in a ejs file in Angular如何在Angular的ejs文件中正确引用js文件
【发布时间】:2016-01-14 03:27:56
【问题描述】:

这是我的项目结构:

公开 -js --angular.min.js --angularApp.js 模板 - 意见 --index.ejs

这是我的 index.ejs 文件:

<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 错误。

我尝试将其添加到路由文件夹中的 middleware.js:

app.use("/public/js/angularApp.js", express.static(__dirname + '/public/js/angularApp.js'));

但这没有用,我也尝试使用此路径:

/public/js/

但也没有用。

如何在 ejs 文件中正确引用 Javascript 文件?

【问题讨论】:

    标签: angularjs keystonejs


    【解决方案1】:

    从访问者的角度来看,公用文件夹是您的根目录。所以在你的情况下应该是

    <script type='text/javascript' src="/js/angular.min.js">
    

    【讨论】:

      猜你喜欢
      • 2020-02-01
      • 2017-03-12
      • 2020-07-15
      • 2019-08-22
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      相关资源
      最近更新 更多