While attempting to preprocess some data before navigating to my page, I am forcefully resolving a promise, converting it into a custom object, and then trying to return the custom object to my resolve object.
.state("trip.detail", {
url: '/:tripId',
templateUrl: 'partials/trip/detail.html',
controller: 'TripDetailController',
resolve: {
trainData: function (TripService, $stateParams, $q) {
return TripService.getTripById($stateParams.tripId,function (data) {
console.log("received: " + data);
return {
"relativeTrainId": data.trainId,
"from": new Date(data.departure).toISOString(),
"to": new Date(data.arrival).toISOString(),
"projectId": data.projectId,
"isTrip": true,
"tripId": data.id,
"trajectory": data.trajectory,
"statistics": data.statistics
}
}).$promise;
}
}
});
Everything seems to work fine, except that the 'trainData' being injected into my controller is actually the original 'data' object and not the custom one that I created.
Any idea what might be causing this issue?
Additional information about TripService:
services.factory('TripService', function ($resource) {
function TripService() {
this.tripResource = $resource('rest/trip/:tripId');
}
TripService.prototype.getTrips = function (start, end, project, trainIds, callback) {
return this.tripsResource.query({
projectId: project,
trainIds: trainIds,
from: start,
to: end
}, callback)
}
TripService.prototype.getTripById = function (tripId, callback) {
return this.tripResource.get({
tripId: tripId
}, callback);
}
return new TripService();
});