I'm developing an application in CodeIgniter 3 and I came across the following problem. I want to import the data from the database table and display it on a php page.
In my controller I created the function:
public function relacionar() {
$query = $this->produto->listagem();
return json_encode($query->result());
}
In the file producto.js I created the following factory:
app.factory('ProdutoService', ['$http', '$q', function ($http, $q) {
return {
retornaDados: function () {
var deffered = $q.defer();
$http({url: window.location.origin + '/ged/produto/relacionar', method: 'GET'})
.then(function (response) {
deffered.resolve(response.data);
});
return deffered.promise;
}
};
}]);
I want to add the return to $ scope.list variable, so I proceed as follows:
function ($scope, $http, $log, $timeout, ProdutoService) {
$scope.list = function () {
ProdutoService.retornaDados().then(function (retorno) {
return retorno;
});
};
Instead of getting the response that came from the database, the return receives the function, not the data. Follow the return:
function () {
ProdutoService.retornaDados().then(function (retorno) {
console.log(retorno);
});
}
What should be the correct way to get the data and not the function as a return? Is using codeIgniter interfering with data?
I have tried the function that looks for the data in the database and it is returning a json array.