I’m trying to make paging with ionic 2 + nodejs.
But I have some problems.
I do the paging from node js and I get a JSON with the values of each pagination.
NodeJS
function getPaginateUser(req, res) { let limite = 2; let page = (parseInt(req.params.num_page) - 1) * limite, num_page = parseInt(req.params.num_page), search = req.query.search, count; User .count() .then(date => { count = parseInt((date / limite) + 1); }); User .find() .skip(page) .limit(limite) .then(user => { let context = { user: user, num_page: num_page, count: count } res.status(200).send(context) //res.render('user', context); });
I receive the data on a promise and subscribe them. But if I subscribe to it when I try to call back for page 2, http does not execute the promise. As I can call back the promise to return the new json with the data on page 2.
Ionic2 - provider
getUser2(num_page){ if(this.data){ return Promise.resolve(this.data); }
return new Promise(resolve => { //this.http.get(this.path + '?results=0') this.http.get(this.path + num_page) .map(res => res.json()) .subscribe(data => { this.data = data; resolve(this.data); }); resolve(this.data); }); }
Ionic 2 - ts
private LoadTimeline() { //.then((profile:any[]) =>{ this.TimelineService.getUser(this.num_page) .then(timelines => { this.timeline = timelines; }) .catch(error => { console.log(error); }) }