简体   繁体   中英

Using angularjs in nodejs server-side

I am fairly new to nodejs, just been playing around with it for a while.

Now I would like to use angularjs $compile on server-side. In the end I would like to have an API which receives html and json and compiles it together using angulars syntax.

To go in a little more detail, this is what it looks like in angular: plunkr

$compile(element.contents())(scope);

As you can see the angular function $compile is used to fill a template from a textarea. I would like to use this $compile function on server-side as a webservice.

tl;dr;: I would like to use angularjs as a templating engine for express/nodejs on server-side.

I am having troubles integrating angular. Do you think this is a liable approach at all?

Nope, this is not liable, you are drastically over-thinking your architecture, just create your angular.js application, render it using a standard node.js template engine as jade or ejs . Then in your angular app connect to an api provided by node.js and express, and let angular do it's job and node.js its job.

Each tool is used for his main purpose, angular is used for single-page-application that are communicating with the server side using ($http, $resource, sockets etc...). Node.js is a scripting language mostly used for server side, api creation, other operations.

My advice keep the job simple, playful bu simple, you will sleep better at nights.

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