I was trying to check whenever my form is being edited by writing some fields of it. I read $dirty should work for that task but I can't figure out what I'm missing here:
<!DOCTYPE html>
<html lang=en>
<script src= http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js></script>
<body>
<div ng-app=myApp ng-controller=formCtrl>
<form name = myForm novalidate>
First Name:<br>
<input type=text ng-model=user.firstName><br>
Last Name:<br>
<input type=text ng-model=user.lastName>
<br><br>
<button ng-click=reset()>RESET</button>
</form>
<p> is Form dirty? {{isDirty}}<p>
<p>form = {{user }}</p>
<p>master = {{master}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {firstName:John, lastName:Doe};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
$scope.isDirty = $scope.myForm.$dirty;
});
</script>
</body>
</html>
I'm trying to make the flag isDirty to true whenever the user modifies the form. Thanks