I am using an angularjs array
to store the record data(table rows) received by using the http.get
rest API and printing using an ng-repeat. The problem is whenever there is only one record retrieved through rest API, ng-repeat doesn't print the record. ng-repeat only print the records when API retrieves more than one record.
$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;
alert($scope.details.fieldname);
alert($scope.details[0].fieldname)
}, function(){alert("failure");});
this is my ng-repeat line,
<div class="col-lg-12" ng-repeat="dat in details | filter : { product_name : textname} as results">
<p style="color:#4C97C8;" class="lead"><strong>{{dat.summary}}</strong></p>
</div>
I found where is the problem causing-
1.When rest api throws only one record, i shouldnt use ng-repeat instead i should use scope variable directly in the view and this alert($scope.details.fieldname) inside controller works but not alert($scope.details[0].fieldname).
2.When rest api throws more than one record, i have to use ng-repeat and this alert($scope.details[0].fieldname) works.
How to solve this? How can i show data in view
in both cases?
ng-repeat
is good. Please show us what is insideresponse.data
and try removing the filter