2017-04-27 77 views
0

我有一个模拟的API有一千个记录。我已经实现了无限滚动。我想从API获取20条记录,并只显示10条记录。 我是新来的离子2请建议一些简单的代码。 我正在使用服务。这是在角教程如何从模拟API获取数据在离子2

https://angular.io/docs/ts/latest/tutorial/toh-pt6.html

下面给出同样的例子是代码

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 
import {HeroService} from '../home/services/hero.service'; 
import {InMemoryDataService} from '../home/services/in-memory-data.service'; 
import {Hero} from '../home/services/hero' 


@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class HomePage { 

    heroes:Hero[]; 
    items=['Thor','Batman','Superman','Ironman','Spiderman'] 

    getHeroes() 
    { 
    this.heroservice.getHeroes().then(heroes=>this.heroes=heroes); 
    } 


i:number; 
    constructor(public heroservice:HeroService) { 


    for (let i = 0; i < 10; i++) { 
     this.items.push(this.items[i]); 

    } 
    this.getHeroes(); 
    } 

    doInfinite(infiniteScroll) { 
    console.log('Begin async operation'); 

    setTimeout(() => { 
     for (let i = 0; i < 100; i++) { 
     this.items.push(this.heroes[i].name); 
     } 
    console.log('Async operation has ended'); 
     infiniteScroll.complete(); 
    }, 500); 
    } 

} 
+0

参考this博客文章只是告诉我如何获取仅10个记录和显示它。 – Abhijeet

回答