I'm facing an issue with my email code where it doesn't finish after the function processing its data is completed. It's triggered by NG-click on a button, but none of the usual callback methods seem to be effective.
In Angular, post requests are sent to my express server for mailing purposes.
function processQuote() {
$http({
method : 'POST',
url : '/send' ,
data : mailJson,
headers: { 'Content-type': 'application/json' }
}).success(function(data){
console.log('success!');
}).error(function(err,data){
console.log(err);
});
};
This function loops through a mixed object/array table and generates a mailJson array that will be used for sending emails.
$scope.calculateAll = function(callback){
var mailJson = [];
var amount = 0;
$scope.contact.totalQuote = 0;
for (var i = 0; i < $scope.customers.length; i++) {
if( $scope.customers[i].area != 0) {
$scope.customers[i].total = parseInt($scope.customers[i].area, 10) * parseInt($scope.customers[i].price, 10);
$scope.contact.totalQuote += parseInt($scope.customers[i].total);
mailJson.push($scope.customers[i]);
}
}
mailJson.unshift($scope.contact);
callback(mailJson);
};
Lastly, here is the HTML snippet with ng-click functionality to trigger the process.
<button type="button" ng-click="calculateAll(processform)" class="btn btn-primary">Submit</button>