I'm currently working on a little AngularJS project.
I got this code in my Service.
testApp.service('testService',['databaseService', 'loggedService', '$http', function(databaseService, loggedService, $http){
this.getDetails= function(name){
$http({
method : "GET",
url : "url"
}).then(function mySucces(response) {
return response.data;
}, function myError(response) {
$scope.myWelcome = response.statusText;
});
};
}]);
I'm calling the method from my service in a controller:
testApp.controller('mainController', ['$scope', '$http', 'testService', function($scope, $http, testService){
$scope.details;
$scope.loadDetails= function(val){
$scope.details= testService.getDetails(val);
console.log($scope.details);
console.log(val);
};
}]);
The $scope.loadDetails is being called in my view when a user is typing something in a search field. So it has to auto-update the dropdown.
The response.data in the service returns an array. But the $scope.details in the controller stays undefined. Anyone knows how to return the response.data from the service to the controller?
I already tried returning the response.data outside the $http, but i keep getting undefined in the controller.