Should I ever use ejs or layouts if I am using Angular for the frontend?

I am currently using Sails for the backend, which comes with an ejs view engine and a templating system which is pretty neat. Setting Angular at the front end of things, however, will interfere with these features.

For example, I can't use templates anymore, because if I said that <html ng-app="myApp">

inside layout.ejs

Angular would never initialize.

The same should be included in any ejs templates.

So now I created a file index.html

inside my folder assets

, disabled Sails routes and layouts, and worked completely with Angular. This will be fine for my current project (except I can't get things as neat as I'm used to, the HTML template has to sit there, etc.), but would this be a problem in other projects? Interesting? / p>

In other words, what am I missing by not using ejs? How can I get things from my Sails controllers in my views? Or don't I need it?

+3


source to share


3 answers


At first this question is open to WIDE interpretation based on all kinds of variables.

If you are using APP simply as JSON delivering an API, then you don't really need to use the templating engine. So the basic premise of your question is correct.

However, there are still enough of them to use the templating engine.

For example, you can use EJS to customize your default layout and indexing page for your angular site.



For example I can't use templates anymore because if I say that inside layout.ejs angular will never initialize.

This statement is completely wrong. I am using server render templatse for my index page in SPA to use my version of the application to point to updated assets and template files. This way the old template files won't be cached when my app is updated. Depending on the application, the index page might be the only one using the templating engine, since everything else will use static templates. Others. I have a server that renders my templates using a templating engine (ex: if I want to restrict some aspects of my templates based on the user's role.)

There are other reasons as well. You can try Google Groups for Sails as this is a more open-ended question.

https://groups.google.com/forum/#!forum/sailsjs

+4


source


If you are using Angular for the frontend and SailsJs for the backend, the best practice is to have two different apps, which means you are not using sails to render the views (no EJS prerequisites). AFAIK SailsJS just needs to be used as a REST API and Angular needs to render your views (you can use http.post get put and delete to communicate with your api).



Regards.

+2


source


Since sails.js is purely backend and Angular.js is purely frontend, they can work well together.

All you have to do is place your angular files and logic in

myapp / assets

folder. The assets folder is available by default on the sails server.

You can access it as http: // localhost: 1337 / assets / file_name .

As with ejs, if you are using a javascript framework like Angular.js then this is not a requirement as all JSON apis will be generated in the sails framework and angular will receive the data in JSON format.

+2


source







All Articles