I have the following code, which uses factory:
angular.module("fluxo", ["ngRoute"]);
.factory('factCliente', ['$http', function($http) {
var _getData2 = function(id_empresa) {
return $http.post("php/index.php", id_empresa);
};
return {
getData2: _getData2
}
}])
.controller("fluxoCtrl", function ($scope, $http, factCliente) {
//var id_empresa = {id: id_empresa};
var id_empresa = {id: 1};
factCliente.getData2(id_empresa).then(function(response) {
$scope.mostraTodasContasEntradas = response;
}, function(error) {
console.log("Ocorreu um erro: " + error);
});
});
And the warning that appears on the console is this:
"SyntaxError: Unexpected token ["
Code php:
<?php
function mostraContasEntrada($id_empresa){
header('Content-Type: application/json');
$pdo = conectar();
$this->mostraDadosEntrada=$pdo->prepare(
"SELECT c.categoria, sc.subcategoria, data, valor
FROM entrada e
JOIN cat_entradas c
on c.id_categoria = e.categoria
JOIN sub_cat_entrada sc
on sc.id_subcategoria
WHERE id_empresa=:id_empresa
ORDER BY data DESC");
$this->mostraDadosEntrada->bindValue(":id_empresa", $id_empresa);
$this->mostraDadosEntrada->execute();
$return = array();
while ($r = $this->mostraDadosEntrada->fetch(PDO::FETCH_ASSOC)) {
$dataP = explode("-", $r['data']);
$data = $dataP[2].'/'.$dataP[1].'/'.$dataP[0];
$r['data'] = $data;
$r['valor'] = number_format($r['valor'],2,',','.');
$r['subcategoria'] = utf8_encode($r['subcategoria']);
$return[] = $r;
//echo $data.' '.$r['categoria'].' '.utf8_encode($r['subcategoria']).' '.number_format($r['valor'],2,',','.')."<br>";
echo json_encode($return);
}
}
<?
Calling the class and function:
require_once "../con/conexao.php";
require_once "../classes/contaEntrada.php";
require_once "../classes/contaSaida.php";
$entrada = new contaEntrada();
$saidas = new contaSaida();
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$id_empresa = $request->id_empresa;
$entrada->mostraContasEntrada($id_empresa);
Does anyone know what problem, what syntax error, is this?