import { Component , ViewChild } from '@angular/core' ; import { IonicPage , NavController , NavParams } from 'ionic-angular' ; import { Novel } from '../../common/models/novel' ; import { NovelsService } from '../../providers/novels-service' ; import { LnLoadingController } from "../../common/ln-loading-controller" ; @ IonicPage ( ) @ Component ( { selector : 'page-ln-search-page' , templateUrl : 'ln-search-page.html' , styles : [ 'ln-search-page.scss' ] } ) export class LnSearchPage { @ ViewChild ( "search" ) search : any ; novels : Array < Novel > ; start : number ; count : number ; searchValue : string = "" ; constructor ( public navCtrl , public navParams , public novelsService , private loadingController ) { } ionViewDidLoad ( ) { console . log ( 'ionViewDidLoad LnSearchPage' ) ; this . start = 0 ; this . count = 50 ; } updateNovelList ( ) { return new Promise ( ( resolve , reject ) => { this . novelsService . getNovels ( this . start , this . count , this . searchValue ) . subscribe ( ( novels ) => { this . novels = this . novels . concat ( novels ) ; this . start += novels . length ; resolve ( ) ; } , ( error ) => { resolve ( ) ; } ) ; } ) ; } searchNovels ( keyCode ) { console . log ( "LnSearchPage.searchNovels" , keyCode ) ; if ( keyCode != 13 ) { return ; } this . start = 0 ; return new Promise ( ( resolve , reject ) => { this . loadingController . presentLoadingMessage ( ) ; this . novelsService . getNovels ( this . start , this . count , this . searchValue ) . subscribe ( ( novels ) => { this . novels = novels ; this . start += novels . length ; this . loadingController . hideLoadingMessage ( ) ; resolve ( ) ; } , ( error ) => { resolve ( ) ; this . loadingController . hideLoadingMessage ( ) ; } ) ; } ) ; } }