on my page there is a text box where users enter the username that they want to execute, and after clicking the submit button. what I want to achieve is when the user clicks the submit button, the results should be immediately clicked on the page. With my script, what it does displays only one result, although there may be 10 or more
Js
.controller('search_ctrl',['$scope','$http','$location','$ionicLoading','$ionicPopup','$state','$stateParams','$cordovaToast',function($scope,$http,$location,$ionicLoading,$ionicPopup,$state,$stateParams,$cordovaToast){
$scope.username=localStorage.getItem("username");
$scope.searchresults = [];
$scope.expendsearch=function() {
$ionicLoading.show({template: '<p>Please Wait...</p><ion-spinner></ion-spinner>'});
event.preventDefault();
$http.post("http://localhost/app/templates/spree/sales/expenses/search_results.php",
{'username':$scope.username})
.success(function(data){
$scope.results=data;
{$ionicLoading.hide();}
var search ={"fullname":data[0].reciever, "username":data[0].amount};
$scope.searchresults.push(search);
}).error(function(error){
console.error(error);
});
}
}])
HTML
<div ng-controller="search_ctrl" ng-repeat="item in searchresults track by $index">
{{item.username}}
{{item.fullname}}
</div>
When I change my script to this:
.controller('search_ctrl',['$scope','$http','$location','$ionicLoading','$ionicPopup','$state','$stateParams','$cordovaToast',function($scope,$http,$location,$ionicLoading,$ionicPopup,$state,$stateParams,$cordovaToast){
$scope.username=localStorage.getItem("username");
$scope.searchresults = [];
$scope.expendsearch=function() {
$ionicLoading.show({template: '<p>Please Wait...</p><ion-spinner></ion-spinner>'});
event.preventDefault();
$http.post("http://localhost/app/templates/spree/sales/expenses/search_results.php",
{'username':$scope.username})
.success(function(data){
$scope.results=data;
{$ionicLoading.hide();}
var search ={"fullname":data.reciever, "username":data.amount};
$scope.searchresults.push(search);
}).error(function(error){
console.error(error);
});
}
}])
Nothing is displayed on the page