Looking for a solution
I currently have this code snippet:
let promise = $http.get('/api/users');
Is there a way to extract the parameters from the promise object? Here is what I envision:
let promise = $http.get('/api/users');
let parameters = promise.extractParameters();
/*
parameters = {
method: 'GET',
url: 'api/users',
// and so on.
}
*/
Imagine creating a Pagination service where you can feed in a promise and dynamically update the URL with different parameters (such as moving to the previous or next page).
Thank you.
Edit Request:
Further clarification needed:
I want to pass the primary promise to a PaginationService.
this.paginator = {};
Paginator.create(this.paginator, function (page) {
// This will serve as the main promise
// page = 1
return $http.get('/api/users', {
params: {
page: 1
}
});
});
// PaginatorService
this.create = function (scopePaginator, callback) {
scopePaginator.next = function () {
return callback(scopePaginator.current_page);
};
return callback().then(function (response) {
// The response metadata holds all the necessary data (current_page, etc.)
angular.extend(scopePaginator, response.data);
return scopePaginator;
});
}
This gives an idea of my approach...