Chapter 5: Working with AngularJS forms

by billy roberts

HTML

<script src="https://code.angularjs.org/1.3.2/angular.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="Ctrl">
        <form novalidate name="myform">
            <input name="myinput" ng-model="formdata.myinput" />
        </form>
        <div ng-show="isPristine">
            Enter a value
        </div>  
    </div>
</div>

JavaScript

// use $watch to change the form text once it is not
// no longer pristine

angular.module('myApp', [])
.controller('Ctrl', function($scope) {
    $scope.$watch('myform.myinput.$pristine', function(newval) {
        $scope.isPristine = newval;
    });
});