Reputation: 317
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);
};
Upvotes: 1
Views: 1454
Reputation: 2954
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);
};
Upvotes: 2
Reputation: 181
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);
};
Upvotes: 1
Reputation: 3451
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);
}
Upvotes: 0