Working with $http
service means working with AJAX, the response is asynchronous, that why you got undefined
, I would suggest changing your service and doing something like this:
app.service('getQuizService', function($http) {
var quizArray;
this.setQuizArray = function(quiz){
quizArray = quiz;
};
this.getQuizArray = function(){
return quizArray;
};
this.getQuizContent = function(quizArray){
var promise=$http.post("http://localhost/PHP/getQuizContent.php",
{'quizArray': quizArray}).then(function (response) {
console.log(response);
return response.data;
});
return promise;
};});
then in controller do something like this:
function initialiseQuizContent(quizIdArray){
getQuizService.getQuizContent(quizIdArray).then(function(data){
alert(data);
});
}