One of the more frequent things you have to do in a forms over data application, the kind where AngularJS really shines, is create and validate data entry forms. The basics of this are pretty easy, just create a controller, add a model to the $scope, create an HTML form and add ng-model input elements for each property the user should enter. No big deal there.
However it would be nice if we could do basic validation in the form and disable a submit button if the form is invalid or the user hasn’t made any changes yet. It turns out this is quite easy to do in AngularJS as each HTML from element automatically creates a FormController and this contains a number of properties that tell us what the status of the form is. In this case we are interested in the $pristine which tells us if the user made any changes and the $invalid which tells us the form is considered to be invalid.
Add to this the ng-disabled directive which we can use to automatically disable an input control and we have the last missing piece to automatically enable/disable the form submit button.
Your new post is loading...
Also available:
Getting started with AngularJS
Creating an AngularJS Controller
The AngularJS $scope is not the MVC Model
Using repeating elements in AngularJS
Filtering the data in an AngularJS ngRepeat element