</>
Skip to content
AngularJS lessons (11/28)

AngularJS — Forms

Basic Form

<form ng-submit="submitForm()">
  <input ng-model="user.name" required>
  <input ng-model="user.email" type="email" required>
  <button type="submit">Submit</button>
</form>

Form Validation

<form name="myForm" ng-submit="submitForm()">
  <input name="email" ng-model="user.email" required email>
  <span ng-show="myForm.email.$error.required">Required</span>
  <span ng-show="myForm.email.$error.email">Invalid email</span>
</form>

Validation States

StateDescription
$validForm/field is valid
$invalidForm/field is invalid
$pristineNot modified
$dirtyModified by user

Input Types

<input ng-model="data.text" type="text">
<input ng-model="data.email" type="email">
<input ng-model="data.password" type="password">
<input ng-model="data.number" type="number">
<input ng-model="data.date" type="date">
<input ng-model="data.checkbox" type="checkbox">
<input ng-model="data.radio" type="radio" value="option1">

Select

<select ng-model="selectedCountry">
  <option value="">Select Country</option>
  <option ng-repeat="country in countries" value="{{country.code}}">
    {{country.name}}
  </option>
</select>

Mini Practice

  1. Create a form
  2. Add validation
  3. Display error messages
  4. Handle form submission

Up Next

Continue with Input — working with inputs.

Related Topics

Frequently Asked Questions about Forms

What is Forms in AngularJS?

Forms is a fundamental concept in AngularJS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Forms?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Forms.

Why is Forms important in AngularJS?

Forms is essential for AngularJS development. Understanding this concept will help you write better code and solve real-world problems more effectively.