Angular ng-repeat不显示来自http.get

时间:2019-01-28 11:33:53

标签: angularjs angularjs-ng-repeat

让我们从一个事实开始,即我已经调查了有关该问题的大部分问题,但不幸的是,我找不到答案。

我有这个基本的http.get:

var app = angular.module('myApp' ,[]);
app.controller('MainCtrl', function($scope, $http)
{
  $http.get("http://source.php")
  .then(function(response)
  {
    $scope.results = response.data.records;
  });
});

这会从php文件中获取数据,并将其编码为JSON,如下所示:

{ "records":[
{"itemnumber":"number","description":"item description","something":"somedata"},
{"itemnumber":"number","description":"item description","something":"somedata"}
]}

顺便说一句:我已经通过JSON验证程序检查了整个JSON结果,因此没有任何问题。

数据以HTML格式“打印”,如下所示:

 <tr ng-repeat="item in results">
    <td>{{item.itemnumber}}</td>
    <td>{{item.description}}</td>
    <td>{{item.something}}</td>
</tr>

问题是它不会填充表格。

但是

如果我进入示波器,而不是手动粘贴结果,而不是response.data.records,它将填充表格。

$scope.results = [
{"itemnumber":"number","description":"item description","something":"something"},
{"itemnumber":"number","description":"item description","something":"something"}
];

track by $index进行跟踪无济于事。

角度标签的绑定方式如下:

<html lang="en" ng-app="myApp" >

<div class="row" ng-controller="MainCtrl" >
<table>
     <tr ng-repeat="item in results">
        <td>{{item.itemnumber}}</td>
        <td>{{item.description}}</td>
        <td>{{item.something}}
    </tr>
 </table>
</div>

我确定是我要忽略的东西,我只是弄不清楚那是什么。

@edit

@ImmanuelKirubaharan,谢谢,您问我这导致找到了问题。我以某种方式编辑了source.php,并在那里添加了导致问题的标签。谢谢 ! 如果您想在答案中发表评论,我会很乐意选择它。

0 个答案:

没有答案