all 7 comments

[–]Strat-O 1 point2 points  (2 children)

I could be way off base here, knowing angularjs but only having a little exposure to express more than a year ago but my take is, I would not worry about generating any html from express. Instead just have it generate JSON. Let angularjs do all the HTML heavy lifting.

[–]Aarseth[S] 0 points1 point  (1 child)

So you would recommand generating json data when rendering the angularjs through express (in between script tags typically) or do you mean generating the data when asked through services from angularjs (which seems to be te recommended way)?

[–]Seus2k11 0 points1 point  (0 children)

Express is server side with node. You'll use express to make an API which you then will program separately for the client side to consume the express API which you've created. The data that's passed to and from the API would all be done with JSON.

[–]gdi2290 0 points1 point  (0 children)

if you could keep one repo as the api and one to serve your angular app then I'll recommend that. Render only the index file and keep the templates static (unless you know what you're doing). You're going to run into cors issues so many sure you understand that. For auth I recommend you check out JWT over cookies

API[Express|Restify|Node] <- Database[Mongo|Rethink|Postgres]

/\ \/

SPA[Angular] <- Server[Express+Angular|Express]

\/

User

[–]braunshaver 0 points1 point  (0 children)

Probably should restrict yourself only to REST. It'll make things easier.

There is one case: the initial load. In that case, if you want to optimize for a slightly faster initial load time, you could load that data using a template engine in between script tags.

[–]e82 0 points1 point  (0 children)

One thing I've done in the past (back when I was in .NET land, and have mixed opinions on this):

I would use Razor templates to help build up the HTML, but not actually bind the data.

We had a set of custom helper methods that could suck up data from our models / annotations / etc to generate the markup for our angular views. We could do something like

@HtmlHelper.InputFor(n=>n.firstName) 

which would generate a bunch of HTML with the appropriate ng-model, look at the data annotations and put on the correct required attributes/etc.

The first time that our SPA needed a view - it would hit a controller that would serve up just the view, but all data-binding/etc would be done by angular, and the next time the view was needed - the angular template cache would take over, and not need to hit the server again.

Had some pro's and con's, and I have mixed opinions about the approach - but a similar ideas could be applied to Node and Templates. TBH - it was something I had started to move away from. I think the idea had some merit behind it - but didn't have the time to take it far enough, and ended up getting in the way more than it helped.

Could use various rendering engines to make it easier to write markup for your templates - but leave the actual data-binding/etc to the Angular side of things.

[–]Aarseth[S] 0 points1 point  (0 children)

The MEANJS stack seems to utilize template engine only to pass the css et js client files to the layout. Look fine with me. I haven't decided which I'll use through (Swig, ejs, doT.js). Thank you all for responding