AngularJS Tutorial - Is input dirty








The following code shows how to check if an input element is dirty.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
.changed {<!--from   www.java  2 s.  c o m-->
  background-color: rgb(252, 202, 202);
}
</style>
</head>
<body>
  <div ng-app>
      <form name="myForm">
        <input name="myInput" ng-model="model"
          ng-class="{changed: myForm.myInput.$dirty}">
      </form>
  </div>
</body>
</html>

The code above is rendered as follows: