2017-07-08 41 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; 
    }); 
}