我使用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数组中?
答案 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>