在ng-repeat列表中,我调用函数{{getDetailedData(id)}}来丰富具有更多数据的重复项。在此函数中,我调用执行a-synchronous $ http调用以获取更多数据。这会导致递归行为:a-sync函数被称为infinte。
当我删除a-sync调用时,函数只会被调用,因为列表中的项目是重复的来源。
a-sync调用有一个不错的回调,肯定不会调用原始函数。
需要你的想法。
修改
控制器中的功能:
$scope.getExtraData = function (id) {
sFact.getSpotDetail(id, function (data) {
console.log('getSpotDetail', data);
})
return false;
}
ng-repeat in partial:
<div class="col-lg-4" style="display: block;" data-ng-repeat="cust in spots | filter: query">
<h2 title="{{ cust.title }}">{{ $index + 1 }} {{ cust.title }}</h2>
{{ getExtraData(cust.id) }}
</div>
同步功能sFact(ory)
factory.getSpotDetail = function(id, callback) {
var data = 'id=' + id;
$http({
url: "php/get_venue.php",
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data: data,
method: "POST"
}).success(callback);
}