简体   繁体   English

如何通过不同的目录引用角度控制器

[英]How to reference angular controllers through different directories

Okay, here goes. 好的,这里有。 I started learning my first node.js/MEAN application last night, and found this tutorial to get me started with the basics: https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular 我昨晚开始学习我的第一个node.js / MEAN应用程序,并发现本教程让我从基础开始: https//scotch.io/tutorials/creating-a-single-page-todo-app-with-节点和-角

So I went through that and got the app up and running pretty easily and I figured for the next step I'd try and break things out into a more modular structure. 所以我经历了这个并且很容易地启动并运行应用程序,我想下一步我会尝试将事情分解为更模块化的结构。 So this is what I was going for: 所以这就是我的目标:

-app
--controllers
---core.js
--models
---todo.js
--views
---index.html
-public
-routes
--todo.js
models.js
package.json
routes.js
server.js

So I pretty much got everything working with this structure at this point but the one thing I can't get working right is index.html doesn't work with core.js anymore. 所以我在这一点上几乎都使用了这个结构但是我无法正常工作的一件事是index.html不再适用于core.js。 So in the index file I used to have: 所以在我以前的索引文件中:

<script src="core.js"></script>

And I updated that to be: 我更新了以下内容:

<script src="../controllers/core.js"></script>

to work with the new structure. 使用新结构。 For some reason that breaks the app and it doesn't load core.js properly anymore. 由于某种原因打破了应用程序,它不再正确加载core.js。 But if I put them into the same directory again and revert the src on the script tag it works again. 但是,如果我再次将它们放入同一目录并恢复脚本标记上的src,它将再次起作用。 That's the only thing keeping me from finishing. 这是阻止我完成任务的唯一因素。 Any insights or help would be greatly appreciated. 任何见解或帮助将不胜感激。

I updated my server config to have app.use(express.static(__dirname + '/app')); 我更新了我的服务器配置以使用app.use(express.static(__dirname + '/app')); and it seems like that fixed it 似乎修好了它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM