这是 Angular 和 php 代码。控制台中没有错误,仍然没有在部分模板中获取数据。我检查了我的 PHP 连接,虽然数据没有显示在我的部分模板中,但它工作正常。请帮助我解决问题,提前谢谢你。
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>
弹出数据.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);
?>
脚本.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);
}
}]);
最佳答案
试试这个:
<td>{{ item.name }}</td>
<td>{{ item.price }}</td>
<td>{{ item.mealType }}</td>
代替:
<td>{{ item.Name }}</td>
<td>{{ item.Price }}</td>
<td>{{ item.MealType }}</td>
关于php - 未在部分模板中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47573090/