I'm trying to chain two http calls. The first one returns a set of records and then I need to get finance data for each of them.
flightRecordService.query().$promise.then(function (flightRecords) {
$scope.flightRecords = flightRecords;
for (var i = 0; i < $scope.flightRecords.length; i++) {
$scope.flightRecords[i].financeDocument =
financeDocumentService
.isReferencedDocumentIdCompensated({
id: $scope.flightRecords[i].id
}).$promise.then(
function (data) {
return ({
'isCompensated': data.headers['compensated']
});
}
);
console.log($scope.flightRecords);
}
});
This is the FlightRecord object:
$$hashKey: "object:27"
aircraft: {id: 100, registration: "LV-OEE", model: "152", status: "ACTIVE", brand: "Cessna", …}
amountOfHours: 1
canceled: false
closed: false
crew: [Object] (1)
destiny: null
endFlight: "2017-01-06T20:54:05.296"
financeDocument: d
--> $$state: {status: 1, value: {isCompensated: "false"}}
--> d prototipo
id: 100
landings: 0
nature: "LDI"
opened: true
origin: null
purpose: "VP"
startFlight: "2017-01-06T19:44:05.296"
status: "OPENED"
type: "ENT"
financeDocument object has not the structure I expect... I need a the following format:
...
endFlight: "2017-01-06T20:54:05.296"
financeDocument: { isCompensated: "false" }
id: 100
...
What I need to change to get that?
Thanks a lot!!
Why not just set it on the original object?
flightRecordService.query().$promise.then(function (flightRecords) {
$scope.flightRecords = flightRecords;
for (var i = 0; i < $scope.flightRecords.length; i++) {
(function(record) {
financeDocumentService
.isReferencedDocumentIdCompensated({
id: $scope.flightRecords[record].id
}).$promise.then(
function (data) {
$scope.flightRecords[record].financeDocument = {
'isCompensated': data.headers['compensated']
}
});
})(i)
console.log($scope.flightRecords);
}
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments