import { Component } from "@angular/core"; import { IonicPage, NavController, NavParams, Refresher, InfiniteScroll, App } from "ionic-angular"; import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api"; import { ProfilePage } from "../profile/profile"; @IonicPage() @Component({ selector: "page-search-results-users", templateUrl: "search-results-users.html" }) export class SearchResultsUsersPage { keyword: string; nextPage: number = 2; users: any[] = []; constructor( public navCtrl: NavController, public navParams: NavParams, private appCtrl: App, private twitter: TwitterApiProvider ) { this.keyword = navParams.data; } async ionViewDidLoad() { if (this.keyword.length) { this.users = await this.twitter.searchUsers(this.keyword); } } showProfile(userId) { this.appCtrl.getRootNav().push(ProfilePage, { userId }); this.nextPage = 2; } doRefresh(refresher: Refresher) { this.twitter.searchUsers(this.keyword).then(users => { this.users = users; this.nextPage = 2; refresher.complete(); }); } loadMore(infiniteScroll: InfiniteScroll) { this.twitter.searchUsers(this.keyword, this.nextPage).then(users => { this.users = this.users.concat(users); infiniteScroll.complete(); this.nextPage = this.nextPage + 1; }); } }