I\'m trying to use Angular\'s built-in form functions, specifically setPristine()
to clear the form on user submit. My controller has access to $scope.new
$setPristine
only marks the form as being $pristine
, which is useful for validation-driven expressions and CSS (e.g. .ng-dirty
)
So, $setPristine
does not clear the form's controls. In fact, it wouldn't even know how to do that. Consider, that to "clear" could mean different things to different models. "Clear" could mean ""
, or undefined
, or null
, or anything at all that a custom input control that works with ngModel
could mean.
So, to properly clear the form is to modify the View Model that drives the form to whatever definition of "clear" it needs. In most cases - yours included - it is just a matter of setting the View Model to a new object:
$scope.submit = function(place) {
$scope.newForm.$setPristine();
$scope.newForm.$setUntouched();
// clear the form
$scope.place = {};
};