简体   繁体   中英

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

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. 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. But if I put them into the same directory again and revert the src on the script tag it works again. 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')); and it seems like that fixed it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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