2017-07-08 42 views
0

我正在開始使用Angular和PHP。我有一個JSON數組,這通過0​​調用將PHP文件發送到AngularJS函數,但我無法在函數js中獲取JSON數組值。如何在角度js表中顯示對象數組php?

與控制檯日誌JSON結果:

ConsoleLog result

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; 
      }); 
} 

}]); 

PHP表:

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

'$ scope.clients =數據;'==>'$ scope.clients = data.data;' –

+0

_Small point_'的foreach ($結果爲$ row){$ out [] = $ row; } echo json_encode($ out);'___爲什麼不只是''json_encode($ result);'___並保存所有浪費的CPU週期____ – RiggsFolly

回答

0

你應該訪問響應data財產,

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