function getBusTimetable() {
var waiting = $q.defer();
var busData = $http.get('https://bus.data.je/latest');
busData.success(function(response) {
waiting.resolve(response);
});
busData.error(function(error) {
waiting.reject(error);
});
return {
getAllTimes: function() {
return waiting.promise;
},
filterByTimetableType: function(type) {
_data = waiting.promise;
return _data.filter(function (el) {
el = el[0];
return el.MonitoredVehicleJourney.DirectionRef == type;
});
}
}
}
When I call either of the above functions, it returns a promise object with methods like finally
, catch
, and then
, instead of the actual resolved value. How can I correct this behavior?