-1
var appCounts = 0;
applicationsService.getApplicationCountByJob(job.id).then((appcount) => {
    appCounts = appCounts + appcount;
});
company.applications = appCounts;

appCount has lost value in company.applications = appCounts;

Please let me know how to solve that issue.

PPShein
  • 13,309
  • 42
  • 142
  • 227

1 Answers1

0

your function getApplicationCountByJob is probably asynchronous, meaning

company.applications = appCounts;

gets executed before

appCounts = appCounts + appcount;

move inside another then to get it work:

var appCounts = 0;
applicationsService.getApplicationCountByJob(job.id)
.then((appcount) => {
    appCounts = appCounts + appcount;
})
.then(() => {
  company.applications = appCounts;
});
Regis Portalez
  • 4,675
  • 1
  • 29
  • 41