I have a list of office ids in an array. I loop through that array and use HTTP request services to get a name associated with the id. It passes back a promise which I learned that I have to use .then to unwrap it.
this.officeID = [100, 200, 300];
this.offices = [];
for (x in this.officeID) {
OfficeService.getOfficeName(x).then(function (data) {
this.offices.push([data, x]);
});
};
The result that I desire is
[["Office1", 100], ["Office2", 200], ["Office3", 300]];
but what I got back was
[["Office1", 300], ["Office2", 300], ["Office3", 300]];
It seems like the service call is waiting for everything to get passed in to finish.