Here is the code snippet that is facing an issue in assigning return values to the scope variable.
app.factory("appService",function($http){
var promise;
var lists = {
async: function() {
var promise = $http.get("http://localhost:81/hrms/public/languagesService").then(function (response) {
return response.data;
});
return promise;
}
};
return lists;
});
The $http
get request returns a successful response with status code 200. Below is how the service is utilized in the controller:
app.controller("AppCtrl",function(appService,$scope,$http,$filter) {
$scope.language = "";
var sortingOrder = 'id';
$scope.sortingOrder = sortingOrder;
$scope.reverse = false;
$scope.filteredItems = [];
$scope.groupedItems = [];
$scope.itemsPerPage = 4;
$scope.pagedItems = [];
$scope.currentPage = 0;
$scope.items = [];
$scope.itemlist = function() {
appService.async().then(function(d){
$scope.data = d;
});
}
$scope.items = $scope.itemlist();
However, the $scope.items
variable remains empty. I need help on how to populate $scope.items
with the response data from $http.get()
. Attempting to use $scope.items.push(d)
did not yield any results...
My goal is for $scope.items
to store the data retrieved from $http.get()
.