Ionic framework 如何在ionic 2中从模拟Api获取数据

Ionic framework 如何在ionic 2中从模拟Api获取数据,ionic-framework,Ionic Framework,我有一个模拟API,有上千条记录。我已经实现了无限卷轴。我想从API中获取20条记录,只显示其中的10条。 我是离子2的新手,请推荐一些简单的代码。 我正在使用服务。角度教程中给出了相同的示例 下面是代码 import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import {HeroService} from '../home/services/hero.service

我有一个模拟API,有上千条记录。我已经实现了无限卷轴。我想从API中获取20条记录,只显示其中的10条。 我是离子2的新手,请推荐一些简单的代码。 我正在使用服务。角度教程中给出了相同的示例

下面是代码

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);
  }

}
从'@angular/core'导入{Component};
从'ionic angular'导入{NavController};
从“../home/services/hero.service”导入{HeroService};
从“../home/services/in-memory data.service”导入{InMemoryDataService};
从“../home/services/Hero”导入{Hero}
@组成部分({
选择器:“主页”,
templateUrl:'home.html'
})
导出类主页{
英雄:英雄[];
items=[‘雷神’、‘蝙蝠侠’、‘超人’、‘铁人’、‘蜘蛛侠’]
getHeroes()
{
this.heroservice.getheromes().then(heromes=>this.heromes=heromes);
}
i:编号;
建造商(公共服务:heroservice){
for(设i=0;i<10;i++){
this.items.push(this.items[i]);
}
这个。getheros();
}
陶粒(无限滚动){
log('Begin async operation');
设置超时(()=>{
for(设i=0;i<100;i++){
this.items.push(this.heromes[i].name);
}
log('异步操作已结束');
无限滚动。完成();
}, 500);
}
}

请参阅

的博客文章,告诉我如何只获取10条记录并显示它。