File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 77< ion-header >
88
99 < ion-navbar >
10- < ion-title > Search</ ion-title >
10+ < ion-title > Search : {{ searchQuery }} </ ion-title >
1111 </ ion-navbar >
1212
1313</ ion-header >
@@ -47,4 +47,7 @@ <h2> {{ product.title }} </h2>
4747 </ button >
4848 </ ion-item >
4949 </ ion-list >
50+ < ion-infinite-scroll (ionInfinite) ="loadMoreProducts($event) ">
51+ < ion-infinite-scroll-content > </ ion-infinite-scroll-content >
52+ </ ion-infinite-scroll >
5053</ ion-content >
Original file line number Diff line number Diff line change 11import { Component } from '@angular/core' ;
2- import { NavController , NavParams } from 'ionic-angular' ;
2+ import { NavController , NavParams , ToastController } from 'ionic-angular' ;
33import * as WC from 'woocommerce-api' ;
44
55@Component ( {
@@ -11,8 +11,9 @@ export class SearchPage {
1111 searchQuery : string = "" ;
1212 WooCommerce : any ;
1313 products : any [ ] = [ ] ;
14+ page : number = 2 ;
1415
15- constructor ( public navCtrl : NavController , public navParams : NavParams ) {
16+ constructor ( public navCtrl : NavController , public navParams : NavParams , public toastCtrl : ToastController ) {
1617 console . log ( this . navParams . get ( "searchQuery" ) ) ;
1718 this . searchQuery = this . navParams . get ( "searchQuery" ) ;
1819
@@ -33,4 +34,25 @@ export class SearchPage {
3334 console . log ( 'ionViewDidLoad SearchPage' ) ;
3435 }
3536
37+ loadMoreProducts ( event ) {
38+
39+ this . WooCommerce . getAsync ( "products?filter[q]=" + this . searchQuery + "&page=" + this . page ) . then ( ( searchData ) => {
40+ this . products = this . products . concat ( JSON . parse ( searchData . body ) . products ) ;
41+
42+ if ( JSON . parse ( searchData . body ) . products . length < 10 ) {
43+ event . enable ( false ) ;
44+
45+ this . toastCtrl . create ( {
46+ message : "No more products!" ,
47+ duration : 5000
48+ } ) . present ( ) ;
49+
50+ }
51+
52+ event . complete ( ) ;
53+ this . page ++ ;
54+
55+ } ) ;
56+ }
57+
3658}
You can’t perform that action at this time.
0 commit comments