Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the conceptual difference between AngularJS and view template engines in NodeJS?

I'm having hard time to make the difference between view template engines, such as EJS and AngularJS. I do understand concept behind view template engines, but I was thinking that Angular is pretty much the same. While building project with IntelliJ, it offered me to make structure of application which is provided by express and to chose view template engine. Since I'm not bothered with HTML syntax, I went with EJS rather than Jade. Now, since I have more user roles, I need to change the view according to role of the user. I tried to do it with EJS with control flow (if-then), but found documentation on EJS really poor. That's why I decided to check the AngularJS since all my colleagues are using it.

As far as I understand till now, I'll have controllers in AngularJS which can control how the view should look like and which data should be filled in.

Do I need view template engine when using AngularJS at all? Are there any benefits?

My code makes use of routes and looks somehow like this now:

/* GET /register page. */
router.get('/', function(req, res) {
    res.render('enter.html');
});

(I've made .html extension to be rendered with EJS)

So, I won't use res.render() anymore and will make usage of controllers and views supported with AngularJS?

like image 616
Tommz Avatar asked Jul 29 '14 21:07

Tommz


2 Answers

In my experience with Angular your web server exposes an API and serves static files, that's it. No need to construct HTML responses with server side processing, just serve the data your application needs. I tend to think of my Angular client as disconnected from the backend as any other client (iOS, Android, etc).

like image 143
Andy Gaskell Avatar answered Oct 17 '22 03:10

Andy Gaskell


you can see Express.js as server side app or server which listens for client requests, assembles the html page and sends it as reply to client. Similar to let's say Codeigniter in PHP world. You can user plain HTML or you can use Jade or other templating language.

On other hand AngularJs is client side technology. You use it to create what is called single web application which means that DOM modification is happening on client side and the app exchange with server only data. If your concern is template it is plain html.

like image 34
webduvet Avatar answered Oct 17 '22 02:10

webduvet