Hacker News new | ask | show | jobs
by heme 4796 days ago
Thanks for the post. I'm at the beginning stages of planning a large single-page web application. I'm very interested in a Google-backed framework, but I continue to have concerns when reviewing tutorials like these. I'm genuinely interested in hearing thoughts on the points below.

Here are some of my concerns...

1. Spaghetti Code. "... AngularJS let you execute expressions directly within your HTML pages." Why do I want JavaScript code in my HTML at all? I normally like absolutely clean HTML templates for two main reasons: 1) They can be used & rendered anywhere 2) they are easier to maintain.

2. AngularJS Directives seem to mix control structures & Code inside HTML templates. This seems difficult to maintain... <div data-ng-repeat="user in users"> ... </div> JavaScript can do loops and most developers understand that. data-ng-repeat is only understood by AngularJS, which means this template will always need to be rendered by AnglularJS. Also, is the template forever tied to a "users" collection? What if I would like to reuse the template for "clients"?

    <div data-ng-repeat="user in users" data-ng-show"=user.gender == 'female'">
    ...
    </div>
Again, code is mixed in with the HTML template. We moved away from <a href="#" onclick"alert('What is up?');"> a long time ago (I realize my example is an event, but I think it still holds true.) . Also, what does this code do behind the scenes: add "display:none", add "visibility:hidden", or add a CSS class? Where do I change the behavior. It feels like this code belongs in a controller/view with the rest of my code.

3. It seems as though the debate of DOM based rendering vs string based rendering is still going on, but do I have a choice with AngularJS? Right now, I'm not a fan string based rendering on the front-end because it locks me into a specific rendering engine (e.g. Handlebars, Mustache, Underscore etc.). Also, if you have no {{tokens}} in your templates you can render them on the server and then later update them on the front-end (I see the AngularJS devs say this is bad, but hybrid can be useful for security, SEO) . There are a number of DOM based templating engines out there. One I like very much is transparency. They have a great FAQ on this topic:

https://github.com/leonidas/transparency/wiki/Frequently-Ask...

4. "Using proper separation of concerns, controllers should never contain anything related to the DOM." Why is this the case? When would you ever use your controller outside of controlling the DOM in a Template? Is AngularJS's view that the Controller contains the event-handling function, but the View/Template does the binding?