Guest User

Untitled

a guest
Nov 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <ion-content padding>
  2. <ion-searchbar (ionInput)="getItems($event)" placeholder="" ></ion-searchbar>
  3. <ion-list>
  4. <button ion-item *ngFor="let item of items" (click)="itemTapped($event, item)">{{ item }}</button>
  5. </ion-list>
  6. </ion-content>
  7.  
  8. export class SearchPage {
  9. searchQuery: string = '';
  10. items: string[];
  11.  
  12. constructor(public navCtrl: NavController, public navParams: NavParams) {
  13. this.initializeItems();
  14. }
  15.  
  16. initializeItems() {
  17. this.items = [
  18. 'item 1',
  19. 'item 2',
  20. ];
  21. }
  22.  
  23. getItems(ev: any) {
  24. this.initializeItems();
  25.  
  26. let val = ev.target.value;
  27.  
  28. if (val && val.trim() != '') {
  29. this.items = this.items.filter((item) => {
  30. return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
  31. })
  32. }
  33. }
  34.  
  35. itemTapped(event, item) {
  36. this.navCtrl.push(
  37. SearchPage, {item: item}
  38. );
  39. }
  40. }
Add Comment
Please, Sign In to add comment