Reputation: 123
On button click I am invoking a method Getdata(); but the problem is when the page is loaded for the first time, if I click on the button then I get "HTTP error" response. but if I click on the button again then it shows success response.
HTML
<button type="submit" class="btn btn-primary form-inline inline-Magrin" ng-click="Getdata()">Search</button>
JS
$scope.Getdata = function () {
if (($scope.NumberOfrecords > $scope.TotalRecords) && ($scope.TotalRecords != 0)) {
alert("Search record count should not be greater than total records");
return;
}
debugger;
$http({
url: '/scrap/Resultdata',
method: "GET",
params: {
Searchbox: $scope.Searchbox,
Category: $scope.Category,
NumberOfrecords: $scope.NumberOfrecords
}
}).then(
function successCallback(response) {
response = $scope.filterRecord(response);
debugger;
$scope.data = response.data.ResponseItems;
$scope.TotalRecords = response.data.TotalResults;
$scope.tableParams = new NgTableParams({
page: 1,
count: 10
}, {
data: $scope.data
});
},
function errorCallback(response) {
debugger;
alert("error");
});
}
Upvotes: 1
Views: 2526
Reputation: 197
if you are having the submit as type, then you need to add the tags in the html,
and in form -------- OnSubmit=GetData()
Please try using type=button instead
Upvotes: 1
Reputation: 123
button type was "submit", it should be "button"
<button type="button" class="btn btn-primary form-inline inline-Magrin" ng-click="Getdata()">Search</button>
Upvotes: 2