Database data does not appear on the screen, using angular and php

Asked

Viewed 173 times

0

This is my Angular Code:

<script>
    angular.module("fluxo", ["ngRoute"]);

    angular.module("fluxo").config(function ($routeProvider) {
        $routeProvider.when("/entradas", {
            templateUrl: "views/entradas.html",
            controller: "fluxoCtrl"
        })
        .when("/saidas", {
            templateUrl: "views/saidas.html",
            controller: "fluxoCtrl"
        })
        .otherwise({redirectTo: "/index"});
    })

    .factory('pegaContas', ['$http', function($http) {
        var _getContas = function(id_empresa) {
            return $http.post("php/index.php", id_empresa);
        };

        return {
            getContas: _getContas
        }
    }])

    .controller("fluxoCtrl", function ($scope, $http, pegaContas) {

        //var id_empresa = {id_empresa: id_empresa};
        var id_empresa = {id_empresa: 1};
        pegaContas.getContas(id_empresa).then(function(data) {
            $scope.mostraTodasContasEntradas = data;
            console.log(data);
        }, function(error) {
            console.log("Ocorreu um erro: " + error);
        });

    });
</script>

And this is my HTML page, where the data should appear:

<div class="container">
    <div class="col-md-3">
        <table class="table table-striped">
            <tr>
                <th>Data</th>
                <th>Categoria</th>
                <th>Subcategoria</th>
                <th>Valor</th>
                <th>Forma pgto.</th>
                <th>Editar</th>
                <th>Excluir</th>
            </tr>
            <tr ng-repeat="conta in contas">
                <td>{{conta.data}}</td>
                <td>{{conta.categoria}}</td>
                <td>{{conta.subcategoria}}</td>
                <td>{{conta.valor}}</td>
                <td>{{conta.forma_pagamento}}</td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
</div>

And yes, I’ve done tests and the data is coming from the bank.

Array return: inserir a descrição da imagem aqui

1 answer

1


That part here:

ng-repeat="conta in contas"

The second option must refer to $Scope. In your case, it would be:

$scope.mostraTodasContasEntradas = data.data;

Stuck like this:

ng-repeat="conta in mostraTodasContasEntradas "
  • I get it, I’m gonna try

  • Only this appeared on the screen "{"id_empresa":1}" heheheh

  • Can show your array?

  • I edited the post, it’s like you suggested.

  • Array where does data come from? php?

  • In this case, the array that is being assigned to the "show"

  • Ta in the code I posted above.

  • In this case, this console.log(data); what it shows on the console?

  • The data coming from the bank.

  • You want me to put it here, how they’re coming?

  • This, to know if the array is "readable" for the way you are inserting into html

  • 0: Object Category: "Occasional Rentals/Sale Imob." Date: "04/11/2015" forma_payment: "Blabla" subcategory: "Occasional Rentals/Sale Imob." Value: "100,00"

  • I put a print here in the post for you to see the array.

  • I edited the answer, change the value of $Scope to $scope.mostraTodasContasEntradas = data.data;

  • Perfect! Closed, are appearing... But pq put date.date?

  • By the way PHP returns. It returns in this logic data = array -> objects. Then just reference the name of the array and then access it. = D

Show 11 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.