Forms

Forms are a core part of sending data to a server in HTML. As a result of this, Angular has some extra features that work with forms.

ngModel

Each form input will need ngModel defined to store the value in the scope. See Directives, ngModel for more information.

Here is a simple form that binds two text inputs:

<form name="form">
  First Name: <input type="text" name="firstname" ng-model="data.firstName" />
  Last Name: <input type="text" name="lastName" ng-model="data.lastName" />
</form>
{{data.firstName}} {{data.lastName}}

CSS classes

Angular will automatically add CSS classes to the form and elements that you can then target with CSS. Here is the list of CSS classes and when they are applied:

  • ng-valid: This denotes that the form or element is valid ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.