Skip to content

Commit 8591979

Browse files
Lec 49
1 parent b07097c commit 8591979

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/pages/search/search.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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>

src/pages/search/search.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { NavController, NavParams } from 'ionic-angular';
2+
import { NavController, NavParams, ToastController } from 'ionic-angular';
33
import * 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
}

0 commit comments

Comments
 (0)