Php 当列出3时,ANGULARJS结果消失

Php 当列出3时,ANGULARJS结果消失,php,html,mysql,angularjs,angularjs-ng-repeat,Php,Html,Mysql,Angularjs,Angularjs Ng Repeat,我的查询搜索餐厅数据库中的所有菜肴 <?php include('base.php'); $data = array(); $result = mysql_query("SELECT nombre FROM platos WHERE tipo = 'principal'",$connect); if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_assoc($result)){ $data[] =

我的查询搜索餐厅数据库中的所有菜肴

<?php
include('base.php');
$data = array();
$result = mysql_query("SELECT nombre FROM platos WHERE tipo = 'principal'",$connect);
if(mysql_num_rows($result) > 0){
    while($row = mysql_fetch_assoc($result)){
        $data[] = $row;
    }
} else {
    echo "0 results";
};
echo json_encode($data);
mysql_close($connect);
?>
最后,我将其打印到我的html代码中:

<div id="agregarpedido_table_item" ng-repeat="principal in principals">
   <p id="agregarpedido_table_item_p">{{principal.nombre}}</p>
   <div id="agregarpedido_table_item_command">
     <p>{{principal.cant}}</p>
     <div class="selectors">
       <input type="button" value="+" ng-click="principal.cant = principal.cant + 1">
       <input type="button" value="-" ng-click="principal.cant = principal.cant - 1">
     </div>
   </div>

{{{principal.nombre}

{{principal.cant}


问题是,当我的数据库中有两个以上的结果与tipo:principal匹配时,html就会消失,并且不会显示任何内容。最糟糕的是,控制台不会抛出任何错误,就好像这是正常的一样。有什么想法吗?

由于SQL查询只返回一个名称数组,angular可能会在ng repeat中抛出无重复错误

尝试按如下方式格式化ng repeat:
ng repeat=“主体中的主体按$index跟踪”

您的主体可能有两个或多个非唯一名称,因此angular会抛出无重复错误。作为参考,使用track by$index方法有助于提高循环中的渲染/绑定性能

这是一个jsbin


希望它能起作用

我从未找到答案,但当我重新启动电脑时,错误就消失了

<div id="agregarpedido_table_item" ng-repeat="principal in principals">
   <p id="agregarpedido_table_item_p">{{principal.nombre}}</p>
   <div id="agregarpedido_table_item_command">
     <p>{{principal.cant}}</p>
     <div class="selectors">
       <input type="button" value="+" ng-click="principal.cant = principal.cant + 1">
       <input type="button" value="-" ng-click="principal.cant = principal.cant - 1">
     </div>
   </div>