Advertisement
filhotecmail

Ts.Homets

May 14th, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component } from '@angular/core';
  2. import { NavController } from 'ionic-angular';
  3. import { RestApiProvider } from '../../providers/rest-api/rest-api';
  4.  
  5. @Component({
  6.   selector: 'page-home',
  7.   templateUrl: 'home.html'
  8. })
  9. export class HomePage {
  10.  
  11.   data: any;
  12.   produtos: string[];
  13.   errorMessage: string;
  14.   page = 1;
  15.   perPage = 0;
  16.   totalData = 0;
  17.   totalPage = 0;
  18.  
  19.   constructor(public navCtrl: NavController, public restApi: RestApiProvider) {
  20.     this.getProdutos();
  21.   }
  22.  
  23.   getProdutos() {
  24.     this.restApi.getprodutos()
  25.        .subscribe(
  26.          res => {
  27.            this.data = res;
  28.            this.produtos = this.data.data;
  29.            this.perPage = this.data.per_page;
  30.            this.totalData = this.data.total;
  31.            this.totalPage = this.data.total_pages;
  32.          },
  33.          error =>  this.errorMessage = <any>error);
  34.   }
  35.  
  36.   doInfinite(infiniteScroll) {
  37.    
  38.     setTimeout(() => {
  39.       this.restApi.getprodutos()
  40.          .subscribe(
  41.            res => {
  42.              this.data = res;
  43.              this.perPage = this.data.per_page;
  44.              this.totalData = this.data.total;
  45.              this.totalPage = this.data.total_pages;
  46.              for(let i=0; i<!!...++= {
  47.               this.produtos.push(this.data.data[i]);
  48.             }
  49.           },
  50.           error =>  this.errorMessage = <any>error);
  51.  
  52.       console.log('Async operation has ended');
  53.       infiniteScroll.complete();
  54.     }, 1000);
  55.   }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement