2017-07-08 2 views
0

Je commence avec Angular et PHP. J'ai un tableau JSON, cela envoie le fichier PHP à la fonction AngularJS par appel $http, mais je ne peux pas obtenir des valeurs de tableau JSON dans la fonction js.Comment afficher le tableau d'objets php dans la table angulaire js?

le résultat JSON avec journal de la console est:

ConsoleLog result

fonction php:

foreach ($result as $row) { 
    $out[] = $row; 
} 

echo json_encode($out); 

js:

app.controller('controllerJs', ['$scope', '$http', function($scope,$http){ 
$scope.clients = []; 

$scope.All = function(){ 
    $http.get('/App/getAll.php') 
      .then(function(data){ 
       $scope.clients = data; 
      }); 
} 

}]); 

table php:

<tbody> 
    <tr ng-repeat="item in clients"> 
     <td>{{item.nombre}}</td> 
     <td>{{item.especialidad}}</td> 
    </tr> 
</tbody> 
+1

'$ scope.clients = données;' ==> '$ scope.clients = data.data,' ' –

+0

foreach _Small point_ ($ comme $ row) {$ out [] = $ row; } echo json_encode ($ out); '___Pourquoi pas juste___' json_encode ($ result); '___et sauvegardez tous ces cycles de CPU gaspillés___ – RiggsFolly

Répondre

0

Vous devez accéder au data propriété de la réponse,

$scope.All = function(){ 
    $http.get('/App/getAll.php') 
      .then(function(data){ 
     $scope.clients = data.data; 
    }); 
}