0

I'm setting up a new MEAN stack project and want to use Angular for my front end. I want to use HTML files for my views so I can use Angular in them. I'm having trouble setting the Express 'view engine' to HTML. I found one solution that works here, written by Andrew Homeyer.

But with this method, I'll have to double up all my view templates? For example, index.jade-index.html, planets.jade-planets.html and so on? Is there any better way to do this? Thanks so much guys.

Community
  • 1
  • 1
nickg
  • 151
  • 2
  • 11

1 Answers1

0

I understand your question but Why do you want to use "html" this meaning you don't want to compile the templates or better, you do not want a template engine. This means you will not be able to pass variables to the template. which can be ok, but then why do you want to include the source code in your server app and not just creating a separate app for your angular app?

While if you are looking for a template engine which is like HTML but having some variable parsing you can use Swig http://paularmstrong.github.io/swig/

If you want to use Swig (which are .html files)

var swig = require('swig');

app.engine('html', swig.renderFile);

app.set('view engine', 'html');

http://paularmstrong.github.io/swig/docs/#express here the full docs for express implementation

DevAlien
  • 2,456
  • 15
  • 17
  • Hi DevAlien. Thanks for answering. I was planning to use Express to grab all the variables from Mongo, and then parse them into JSON and send them to Angular. This guy here has a pretty cool tutorial on getting set up: https://www.youtube.com/watch?v=iFsYJG3fGro – nickg Sep 21 '15 at 00:07
  • You can use the express app as an API. And then angular calls that API – DevAlien Sep 21 '15 at 00:10
  • what does that mean? Use Jade or EJS to get the info on the page, and then Angular plays with it? I feel like I hear 'Express as an API' here and there, but i dont see how it would work. Of course Im not looking for you to explain it all, but if youve come across a link or anything, pls pass it on. Im still at the start at putting this all together. Ha everytime i think im progressing, theres another level to it. Thanks – nickg Sep 21 '15 at 00:21