

On the Bleeding Edge: Advanced AngularJS Form Validation - anorborg
http://code.realcrowd.com/on-the-bleeding-edge-advanced-angularjs-form-validation/

======
ianstormtaylor
Can someone who is proficient in Angular explain to me why this many
attributes are required on the form element itself:

    
    
        <form ng-app="LoginApp" ng-controller="LoginController" ng-submit="login()">
    

This leads to my usual reaction to Angular: I'm sure they've got some things
right, and I believe that data binding is the way to go, but holy shit that
code is ugly and verbose. I've been using reactive.js [1] lately with
Component [2] and its incredibly beautiful by contrast:

    
    
        <form data-submit="login">
    

It uses data attributes, functions are handled for you automatically so you
don't have to write the parens all the time, it will fallback to the model
automatically if the view doesn't have a certain property. And the view is
passed in so you don't need to specify what controller or "app" to search for,
which seems way less tightly coupled.

Really it's one of the most beautiful libraries I've ever seen. So why would I
ever want to use Angular?

I'm honestly curious since I've heard so many good things about Angular. It
seems like they need a few more designers who can code on the team--people who
care about the user experience part of API design.

[1]:
[https://github.com/component/reactive](https://github.com/component/reactive)
[2]:
[https://github.com/component/component](https://github.com/component/component)

~~~
jeremya
To answer your question, those attributes are not all required on the form
element. From the docs on ngApp[1]:

    
    
      Use this directive to auto-bootstrap an application. Only  
      one ngApp directive can be used per HTML document. The 
      directive designates the root of the application and is 
      typically placed at the root of the page.
    

The ngController directive gives behavior to a scope. So, in this example, the
behavior of the LoginController is available to everything within the form
element. ngController could be placed on a div that encapsulated the form and
the result would be the same.

The only thing really _required_ on the form element for this example is the
ngSubmit directive. The other two tags can be placed elsewhere.

[1]:
[http://docs.angularjs.org/api/ng.directive:ngApp](http://docs.angularjs.org/api/ng.directive:ngApp)

