1

I know this is a common question , but I am facing problem in this. I am unable to refresh by input fields on button click.

When I am clicking button , the information is sent and added up in a list. So whenever I click it the input fields must get cleared/refresh (not page load).

View:

<div class="input-group">
        <span class="input-group-addon" id="reg_input">Name</span>
         <input type="text" class="form-control" placeholder="Name" ng-model="ff.Name" required>
</div>

<div class="input-group">   
    <span class="input-group-addon" id="reg_input">Block</span>
     <input class="form-control" id="bl" type="text" ng-model="ff.Block" required>
</div>

<div class="input-group">   
    <input type="text" class="form-control" id="ip" type="text" ng-model="ff.IP" ng-maxlength="2" style="width: 30px" required>
</div>
   <a class="btn btn-md btn-primary" ng-click="getClick(ff)">Add</a>

Is there any refresh predefined in bootstrap button ?

EDIT controller:-

$scope.list = {};
                $scope.array_of_Names = [];
              $scope.getClick= function() {
                 $scope.master = angular.copy($scope.ff);
                  $http.post("url", $scope.list).success(function(data) { 
                        $scope.AllData= data;
                        $scope.addInfo.Segments.push($scope.list);
                        $scope.ff.Name = "";
                        $scope.ff.Block= "";
                        $scope.ff.IP= "";
                        $scope.array_of_Names.push($scope.list);
                       console.log("Segment successfully created");

                  },function (data, status, headers, config) { 
                       // growl.error("Something went wrong");
                  });
                     console.log($scope.master);
                };
5
  • what is getClick ? where is the main logic ? Commented Apr 24, 2018 at 7:11
  • Just initialize your forms ng-model value to its default values on click event. Commented Apr 24, 2018 at 7:13
  • @AshishRatan added. Please check Commented Apr 24, 2018 at 7:17
  • @ManishBalodia ok I will try. Commented Apr 24, 2018 at 7:19
  • 1
    $scope.ff= {} will work . inside ur http Commented Apr 24, 2018 at 7:26

3 Answers 3

2

Just Try it!. All property under $scope.ff will be reset.

$scope.ff={};

And you can apply it in your code part like this:

$scope.list = {};
            $scope.array_of_Names = [];
          $scope.getClick= function() {
             $scope.master = angular.copy($scope.ff);
              $http.post("url", $scope.list).success(function(data) { 
                    $scope.ff={};
                    $scope.AllData= data;
                    $scope.addInfo.Segments.push($scope.list);
                    $scope.array_of_Names.push($scope.list);
                   console.log("Segment successfully created");

              },function (data, status, headers, config) { 
                   // growl.error("Something went wrong");
              });
                 console.log($scope.master);
            };
Sign up to request clarification or add additional context in comments.

6 Comments

Ok where I need to put that?
Nope, no changes brother.
@WhoAmI i don't know the full business, but please try to place $scope.ff={}; after success. edited my answer.
could you upload your code to plnkr, i'll try your code later.
Thanks , it is working. $scope.ff={}; should be after push , as it was sending null earlier.
|
1

EDIT:

$scope.getClick= function() {
    $scope.master = angular.copy($scope.ff);
    $scope.ff = {};
    $http.post("url", $scope.list).success(function(data) { 
           $scope.AllData= data;
           $scope.addInfo.Segments.push($scope.list);
           $scope.array_of_Names.push($scope.list);
           console.log("Segment successfully created");
        },function (data, status, headers, config) { 
          // growl.error("Something went wrong");
        }).error(function(err) {
            console.log("Error: ", err);
        });
        console.log($scope.master);
 };

9 Comments

I did that , I have updated the edit but didn't get refreshed.
Are you sure your request enter in successs or error function please make sure in what case enter your request with console.log
Please try this after your console.log($scope.master); write this $scope.ff = {};
You mean to say $scope.list ? yes its successful . But the return data is not these which I am passing . I need to clear input fields before POST happens.
Is there any error you get or somethink like that? If no then please console.log($scope.ff) after $scope.ff = {};
|
0

Try then instead of success

$scope.getClick = function(ff){
  $scope.master = angular.copy($scope.ff);
              $http.post("url", $scope.list).then(function(data) { 
                    $scope.AllData= data;
                    $scope.addInfo.Segments.push($scope.list);
                    $scope.ff.Name = "";
                    $scope.ff.Block= "";
                    $scope.ff.IP= "";
                    $scope.array_of_Names.push($scope.list);
                   console.log("Segment successfully created");

              },function (data, status, headers, config) { 
                   // growl.error("Something went wrong");
              });
                 console.log($scope.master);
}

2 Comments

Tried this but nothing happened. Please check my controller . Accordingly I need to do
Doesn't matter , it's same . Ok I explain Name Block and IP is user input not response. I need to clear this value before POST happens

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.