Bind the summary property elsewhere, and use a two way binding on that, so that when the result is returned from the $http call, you can have it displayed.
<tbody>
<tr data-ng-repeat="pack in packs"
data-ng-show="((authentication.user) && (authentication.user._id == pack.user._id))">
<td data-ng-bind="pack.tracking_number"></td>
<td data-ng-bind="pack.description"></td>
<td data-ng-bind="pack.company"></td>
<td data-ng-bind="{{::get_tracking(pack)}}"></td>
<td data-ng-bind="trackingSummary[packet]"></td>
<td ng-bind=""></td>
</tr>
</tbody>
JS
$scope.trackingSummary = {};
$scope.get_tracking = function (packet) {
if (packet){
$http.post('/tracking', packet).success(function(response) {
$scope.trackingSummary[packet] = response.summary;
}).error(function(response) {
});
}
};
OR:
<tbody>
<tr data-ng-repeat="pack in packs"
data-ng-show="((authentication.user) && (authentication.user._id == pack.user._id))">
<td data-ng-bind="pack.tracking_number"></td>
<td data-ng-bind="pack.description"></td>
<td data-ng-bind="pack.company"></td>
<td data-ng-bind=""></td>
<td data-ng-bind="get_tracking(pack)"></td>
<td ng-bind=""></td>
</tr>
</tbody>
$scope.trackingSummary = {};
$scope.get_tracking = function (packet) {
if (packet && !$scope.trackingSummary[packet.tracking_number]){
$http.post('/tracking', packet).success(function(response) {
$scope.trackingSummary[packet.tracking_number] = response.summary;
}).error(function(response) {
});
}
return $scope.trackingSummary[packet.tracking_number];
};
UPDATE
If you add a function to run when your $scope.packs have loaded in, you could ensure that things only get called once:
JS
$scope.trackingSummary = {};
$scope.get_tracking = function (packet) {
if (packet){
$http.post('/tracking', packet).success(function(response) {
$scope.trackingSummary[packet.tracking_number] = response.summary;
}).error(function(response) {
});
}
};
//after packs loaded
var onLoadedFunc = function () {
for (var i = 0; i < $scope.packs.length; i++) {
$scope.get_tracking($scope.packs[i]);
}
};
//when you know that the packs collection is loaded:
onLoadedFunc();
This should prevent an infinite digest loop, as calling the property of the object would not cause a digest every time like a function would. and if your order of the packs would not change once loaded, you could also pass the index in and set the summary on the object itself:
var onLoadedFunc = function () {
for (var i = 0; i < $scope.packs.length; i++) {
$scope.get_tracking($scope.packs[i], i);
}
};
$scope.get_tracking = function (packet, index) {
if (packet){
$http.post('/tracking', packet).success(function(response) {
$scope.packs[i].summary = response.summary;
}).error(function(response) {
});
}
};
Allowing for HTML like so:
[...]
<td data-ng-bind="pack.summary"></td>
[...]
You could also remove the get_tracking function from scope, as it would only be called by code in the controller, unless you need to update or change the summary without reloading the scope/view