ng-repeat with mysql database data

Asked

Viewed 60 times

0

I have 02 tables in the bank (Prospect and opportunity) the two tables have the prospectId. As I do to display in ng-repeat. I was trying to Inner Join in the php query and returns this error in the angular "Error: [ngRepeat:dupes]". Do you have an example.

/* Lista oportunidade */ 
$scope.listaOportunidades = []; 
var carregaOportunidades = function () { 
 $http.get("models/readOportunidades.php")
     .then(function (response) { 
            $scope.listaOportunidades = response.data; 
      }); 
 }; 
carregaOportunidades();

<?php
require '../../vendor/autoload.php';

use App\controllers\DB\Conn;

$PDO = new Conn;

$query = $PDO->getConn()->prepare('SELECT * FROM tb_prospect INNER JOIN tb_oportunidade ON tb_prospect.prospectId=oportunidadeCliente');
$query->execute();

while ($row = $query->fetch()) {
    $return[]= $row;
}
echo json_encode($return);

1 answer

0

More information is needed to understand what is happening in your code:

  • HTML code where you are using the directive;
  • List returned by your Query;

By error, there are duplicate items (in the understanding of angular) during ng-repeat: https://docs.angularjs.org/error/ngRepeat/dupes

This way, I believe that using the example below will work:

<div ng-repeat="valor in listaOportunidades track by valor.VALOR_UNICO_DO_REGISTRO"></div>

I also suggest that you review the query.

  • This part I’ve managed to solve now returns the data right, I’m able to get the data of the tables with Inner Join. Thanks!

Browser other questions tagged

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