If you want to reset your dirty flag form $ fields after ajax is successful, you must call setPristine () from within your success handler:
$http.post('/ci_angular/api/customers/customer', customer)
.success(function() {
$scope.customerForm.$setPristine();
});
If you want to clear form fields, you must initialize the model inside your controller so that you can bind them to the view and clear them later:
Controller:
function CustomersController ($scope, $http) {
$scope.customer = {};
$scope.customers = [];
$http.get('/ci_angular/api/customers/').success(function(customers){
$scope.customers = customers;
});
$scope.addCustomer = function(customer){
$http.post('/ci_angular/api/customers/customer', customer).success(function() {
$scope.customers.push(customer);
$scope.customer = {};
});
}
}
var app = angular.module('app', []);
app.controller('CustomersController', CustomersController);
HTML
<div ng-app="app" ng-controller="CustomersController">
<form name="customerForm">
customerName:<input type="text" name="name" ng-model="customer.name" /><br />
email: <input type="text" name="email" ng-model="customer.email" /><br />
address: <input type="text" name="address" ng-model="customer.address" /><br />
city: <input type="text" name="city" ng-model="customer.city" /><br />
state: <input type="text" name="state" ng-model="customer.state" /><br />
postalCode: <input type="text" name="postalcode" ng-model="customer.postalCode" /><br />
country: <input type="text" name="country" ng-model="customer.country" /><br />
<button ng-click="addCustomer(customer)">Add Customer</button>
</form>
</div>
source
share