当有一条记录时,角度数组不显示数据

时间:2017-01-06 06:22:19

标签: angularjs angularjs-scope

我使用angularjs array来存储使用http.get rest API接收的record data(table rows)并使用ng-repeat进行打印。问题是只要通过rest API检索到一条记录,ng-repeat就不会打印记录。 ng-repeat仅在API检索多条记录时打印记录。

 $scope.details=[];
  var lrequ = {
    method: 'GET',
    url: "https://example.com/execSQL?sql=mysqlquery",
    headers: {
    "Content-Type": "application/json"
    }
}
$http(lrequ).then(function(response){
    $scope.details=response.data.platform.record;
    }, function(){alert("failure");}); 

这是我的ng-repeat行,

 <div class="col-lg-12" ng-repeat="dat in details | filter : { product_name : textname} as results">

问题是什么?问题出在ng-repeat或$ scope.details数组中?

2 个答案:

答案 0 :(得分:0)

你可以使用ng-if

    <div ng-if="details.length ==0>
    <div class="col-lg-12" ng-repeat="dat in details[0] | filter : { product_name : textname} as results">
    </div>
   <div ng-if="details.length > 0>
    <div class="col-lg-12" ng-repeat="dat in details | filter : { product_name : textname} as results">
    </div>

答案 1 :(得分:-1)

尝试这个我认为它会对你有所帮助:

<div class="col-lg-12" ng-repeat="dat in details track by $index | filter : { product_name : textname} as results">
   <span ng-show="$first">{{dat}}</span>
</div>