I want to know if its possible to return database result through angular method call within an ngRepeat template. To clarify here is my template:
<div class="article-right" ng-repeat="localNews in allLocalNews | limitTo:5">
<div class="article-title">
<p>
On {{localNews.dte | date}}
<a>Number of comment: {{getNumberOfComment(localNews.id)}} </a>
</p>
</div>
and here is my controller, Within my controller I have a method which accepts each id value of results in ngRepeat to fetch the number of comments from the database
$scope.getNumberOfComment = function(id){
var cObj = {id:id}; //get a news number of comments
return $http.post("shared/search/getNumberOfComment.cln.php",cObj).success(function(response){
if(response != "failed"){
return response;
}
}).error(function (response, status) {
console.log(response);
});
}
This scripts makes my browser to freeze as it goes into loop. Any help will be highly appreciated.
$http.postforgetrequest?getmethod on initialization, then display response usingng-repeatin a template. Do not callgetinng-repeat. The first advantage is that you will get all data you want using just one API call, if you have 100newsyou will end up with 100 unnecessary API calls which may make your application very slow. Second, http requests are asynchronous calls, this may give you strange results with using it in the template.