1

I am new to AngularJS and trying to do a project. I have a form which works perfectly. However, there is only one thing that I should do. After adding a customer, I need to clear the form. Because, when the user wants to add a second customer, tthe user sees the previously entered values.

$scope.add = function () {
        $scope.loading = true;
        $http.post('/api/Customer/', this.newcustomer).success(function (data) {
            alert("Added Successfully!!");
            $scope.addMode = false;
            $scope.customers.push(data);
            $scope.loading = false;

        }).error(function (data) {
            $scope.error = "An Error has occured while Adding Customer! " + data;
            $scope.loading = false;
        });
    };
Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189

2 Answers2

1

Try this:

$scope.add = function () {
        $scope.loading = true;
        $http.post('/api/Customer/', this.newcustomer).success(function (data) {
            alert("Added Successfully!!");
            $scope.addMode = false;
            $scope.customers.push(data);
            $scope.loading = false;
            this.newcustomer = {};

        }).error(function (data) {
            $scope.error = "An Error has occured while Adding Customer! " + data;
            $scope.loading = false;
        });
    };
DarkSkull
  • 1,041
  • 3
  • 13
  • 23
-3

You have to manually clear the values of the form elements

This should do it:

delete $scope.newcustomer