---
title: "AngularJs Forms"  
description: "Hi everyone in this blog I’m explaining about AngularJs forms.Introduction:AngularJs enriches form filling and validation, We can use ng-click to hand"  
author: "Anonymous User"  
published: 2015-03-24  
updated: 2018-02-22  
canonical: https://www.mindstick.com/blog/10857/angularjs-forms  
category: "angular js"  
tags: ["angularjs scope", "angularjs model"]  
reading_time: 2 minutes  

---

# AngularJs Forms

Hi everyone in this blog I’m explaining about [AngularJs](https://www.mindstick.com/articles/13081/advantages-disadvantages-of-angularjs-is-that-ideal-for-your-project) forms.

##### Introduction:

##

AngularJs enriches form [filling](https://yourviews.mindstick.com/audio/1303/the-power-of-silence-what-happens-when-you-stop-filling-every-moment) and [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework), We can use ng-click to handle AngularJs click on a [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) and use $dirty and $invalid flags to do the validations in a seemless way. Use novalidate with a form declaration to [disable](https://www.mindstick.com/forum/12901/how-to-disable-enable-input-box-in-aspx-with-value-from-sql) any [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser)-specific validation. Forms [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) make heavy use of angularjs events. Let’s have a quick look on the event first.

##### Events:

##

AngularJS provides [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) events which can be associated with the HTML controls. For example, ng-click is normally associated with the button. Following are supported events in [Angular JS](https://www.mindstick.com/forum/33800/how-to-add-edit-update-record-in-angular-js-in-mvc).

1. ng-click

2. ng-dbl-click

3. ng-mousedown

4. ng-mouseup

5. ng-mouseenter

6. ng-mouseleave

7. ng-mousemove

8. ng-mouseover

9. ng-keydown

10. ng-keyup

11. ng-keypress

12. ng-change

##### ng-click:

##

Reset data of a form using on-click directive of a button.

```
<input name="firstname" type="text" ng-model="firstName" required><input name="lastname" type="text" ng-model="lastName" required><input name="email" type="email" ng-model="email" required><button ng-click="reset()">Reset</button><script>    function studentController($scope) {        $scope.reset = function () {            $scope.firstName = "Kamlakar";            $scope.lastName = "Singh";            $scope.email = "sample@sample.com";        }        $scope.reset();    }</script>
```

##### Validate data:

##

The following can be used to track error.

1. $dirty - [states](https://yourviews.mindstick.com/story/1549/top-indian-states-with-muslim-population) that value has been changed.

2. $invalid- states that value entered is invalid.

3. $error- states the exact error.

##### Example:

##

```
<html><head><title>Angular JS Forms</title><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script><style>table, th , td {  border: 1px solid grey;  border-collapse: collapse;  padding: 5px;}table tr:nth-child(odd) {  background-color: #f2f2f2;}table tr:nth-child(even) {  background-color: #ffffff;}</style></head><body><h2>AngularJS Sample Application</h2><div ng-app="mainApp" ng-controller="studentController"><form name="studentForm" novalidate><table border="0"><tr><td>Enter first name:</td><td><input name="firstname" type="text" ng-model="firstName" required>   <span style="color:red" ng-show="studentForm.firstname.$dirty && studentForm.firstname.$invalid">      <span ng-show="studentForm.firstname.$error.required">First Name is required.</span>   </span></td></tr><tr><td>Enter last name: </td><td><input name="lastname"  type="text" ng-model="lastName" required>   <span style="color:red" ng-show="studentForm.lastname.$dirty && studentForm.lastname.$invalid">      <span ng-show="studentForm.lastname.$error.required">Last Name is required.</span>   </span></td></tr><tr><td>Email: </td><td><input name="email" type="email" ng-model="email" length="100" required><span style="color:red" ng-show="studentForm.email.$dirty && studentForm.email.$invalid">      <span ng-show="studentForm.email.$error.required">Email is required.</span>      <span ng-show="studentForm.email.$error.email">Invalid email address.</span>   </span></td></tr><tr><td><button ng-click="reset()">Reset</button></td><td><button                ng-disabled="studentForm.firstname.$dirty && studentForm.firstname.$invalid ||                                                  studentForm.lastname.$dirty && studentForm.lastname.$invalid ||                                                  studentForm.email.$dirty && studentForm.email.$invalid"                ng-click="submit()">Submit</button></td></tr></table></form></div><script>    var mainApp = angular.module("mainApp", []);     mainApp.controller('studentController', function ($scope) {        $scope.reset = function () {            $scope.firstName = "Kamlakar";            $scope.lastName = "Singh";            $scope.email = "sample@sample.com";        }        $scope.reset();    });</script></body></html>
```

##### Output:

##

![AngularJs Forms](https://www.mindstick.com/blogs/4d8fb45f-ad8d-402a-8ffb-0d04a4ff8abf/images/0a906ecc-d242-43b7-9c73-f43f04330f16.png)

When we have empty every field that time our form give some message like this

![AngularJs Forms](https://www.mindstick.com/blogs/4d8fb45f-ad8d-402a-8ffb-0d04a4ff8abf/images/d35db409-91f7-4ca2-9c58-31f6502a8c10.png)

---

Original Source: https://www.mindstick.com/blog/10857/angularjs-forms

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
