这是Angular和php代码。在控制台中没有错误,仍然没有在部分模板中获取数据。我检查了我的PHP连接并且它工作正常,虽然数据没有显示在我的部分中。请帮助我解决问题并提前感谢。< / p>
menu.html(部分模板)
<div ng-controller="MenuController">
<figure class="menu_jumbotron">
<ul class="breadcrumb">
<li><a href="home">Home</a></li>
<li>Menu</li>
</ul>
</figure>
<div class="menu">
<h1><i>{{title}}</i></h1>
<div class="menu_button">
<figure>
<div>
<span>Breakfast</span>
<span>100% Organic</span>
</div>
</figure>
<figure>
<div>
<span>Lunch</span>
<span>100% Organic</span>
</div>
</figure>
<figure>
<div>
<span>Dinner</span>
<span>100% Organic</span>
</div>
</figure>
<figure>
<div>
<span>Beverages</span>
<span>100% Organic</span>
</div>
</figure>
<figure>
<div>
<span>Desserts</span>
<span>100% Organic</span>
</div>
</figure>
</div>
<div>
<table style="background-color:white; margin-left:500px">
<thead>
<th style="border:1px solid red">Name</th>
<th style="border:1px solid red">Price</th>
<th style="border:1px solid red">Meal Type</th>
</thead>
<tbody>
<tr ng-repeat="item in all_items" >
<td>{{ item.Name }}</td>
<td>{{ item.Price }}</td>
<td>{{ item.MealType }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
popdata.php
<?php
$host = "localhost";
$user = "xxxxxxxx";
$password = "xxxxxxxxxxxx";
$db = "meoan_organics";
$con = new mysqli($host,$user,$password,$db);
if(!$con)
{
die('Unsuccessful Connection');
}
$sql = "SELECT * FROM `meoan_all_food_items`";
$q = $con->query($sql);
$data = array();
if($q->num_rows >0)
{
while($row = $q->fetch_object())
{
$data[] = $row;
}
}
else
{
$data[] = null;
}
$con->close();
echo json_encode($data);
?>
的script.js
/// <reference path="route.js" />
app.controller("MenuController",['$scope', '$http', '$log', function ($scope,$http,$log) {
$scope.title = "Our Menu";
$http.get('database/popdata.php')
.then(function(data){
$scope.all_items = data;
}),function(err){
$log.error(err);
}
}]);
答案 0 :(得分:0)
试试这个:
<td>{{ item.name }}</td>
<td>{{ item.price }}</td>
<td>{{ item.mealType }}</td>
而不是:
<td>{{ item.Name }}</td>
<td>{{ item.Price }}</td>
<td>{{ item.MealType }}</td>