我正在使用PHP后端和AngularJS,在login.php文件中,我有一个查询,我将此查询的结果保存在变量$ result中,而在app.JS中,我把这个结果放在一个cookie中我将它显示在view.html文件中。问题是我得到了Json形式的查询结果,但是我想把它作为表格,所以我可以用ng-repeat在html文件中显示这个结果。
的login.php
$query = 'SELECT * FROM client WHERE (EmailClient = "'.$Email.'" AND mdp= "'.$mdp.'") ';
$q = mysqli_query($connect , $query);
if(mysqli_num_rows($q) > 0 )
{
while($res=mysqli_fetch_assoc($q))
{
$someArray[] = $res;
}
for($i = 0; $i < count($someArray); ++$i)
{
$result["cc"] = $someArray ;
$resultstring=json_encode($result);
$resultstring=str_replace("null", '""', $resultstring);
echo $resultstring;
exit;
}
app.js
app.controller('loginCtrl', function($scope, $location,$state,$http,$window,$rootScope,$cookieStore,$cookies){
$scope.submit = function()
{
data = {
'Email' : $scope.Email,
'mdp' : $scope.mdp
};
$http.post('http://localhost/deb/login.php', data)
.success(function(data, status, headers, config,result)
{
console.log(data);
$state.go('view');
$cookieStore.put('cookie',data.cc);
}
$scope.name=$cookieStore.get('cookie');
});
view.html
<div class="container" ng-controller="loginCtrl">
{{Name}}
</div>
因此,在view.html中,我得到了查询的结果,但是以Json形式,我试图使scope.query = data;在view.html中进行ng-repeat,但我没有得到任何结果。我该怎么办?
答案 0 :(得分:0)
json格式的结果示例
result = [{
name: A,
value: 1
},
{
name: B,
value: 2
},
{
name: C,
value: 3
}]
然后HTML表格
<table>
<thead>
<th>Name</th>
<th>Value</th>
</thead>
<tbody>
<tr ng-repeat= "item in result">
<td>{{item.name}}</td>
<td>{{item.value}}</td>
</tr>
</tbody>
</table>