1
I’m trying to set up a Factory for various requests, but the result is always undefined
, what could be wrong?
My Angularjs:
(function(){
angular
.module("store", ['ui.bootstrap', "ngAnimate", "ngSanitize"])
.controller("homeCtrl", appController)
.factory('httpService', function($http, $q){
return {
getData: getDataHandler
};
function getDataHandler(url, data){
$http({
method: 'POST',
url: url,
data: {'p': data}
}).then(handlerSuccess, handlerError);
};
function handlerSuccess(response){
return response.data
}
function handlerError(response){
if(!angular.isObject(response.data) || !response.data.message){
return $q.reject('Ops! Aconteceu algo errado.');
}
return $q.reject(response.data.message);
}
});
function appController($scope, $http, httpService){
console.info(httpService.getData('php/list.php', null));
$scope.page = httpService.getData('php/list.php', null);
}
})();
My list of examples:
<?php
$p = json_decode(file_get_contents("php://input"))->p;
$list = '{
"title": "Aulas",
"categorias": [{
"nome": "Matemática",
"subcategorias": [
"Algebra",
"Estatística",
"Cálculo I",
"Cálculo II",
"Cálculo III",
"Geometria Analítica"
]
},{
"nome": "Engenharia",
"subcategorias": [
"Materiais",
"Estrutural",
"Elétrica",
"Química"
]
}]
}';
print($list);
What are you sending in the date variable?
– Felipe Santos
the date variable may or may not contain values, regardless
– Rodnei Leal
I tried also with service, since they work in the same way, the result is the same.
– Rodnei Leal