Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ion-content padding>
- <ion-searchbar (ionInput)="getItems($event)" placeholder="" ></ion-searchbar>
- <ion-list>
- <button ion-item *ngFor="let item of items" (click)="itemTapped($event, item)">{{ item }}</button>
- </ion-list>
- </ion-content>
- export class SearchPage {
- searchQuery: string = '';
- items: string[];
- constructor(public navCtrl: NavController, public navParams: NavParams) {
- this.initializeItems();
- }
- initializeItems() {
- this.items = [
- 'item 1',
- 'item 2',
- ];
- }
- getItems(ev: any) {
- this.initializeItems();
- let val = ev.target.value;
- if (val && val.trim() != '') {
- this.items = this.items.filter((item) => {
- return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
- })
- }
- }
- itemTapped(event, item) {
- this.navCtrl.push(
- SearchPage, {item: item}
- );
- }
- }
Add Comment
Please, Sign In to add comment