@Liion wrote:
Hello, I have just created a search bar with several item, and I wish that each item redirects to a specific page, but I do not know how (after search no result).
Here is my codehtml:
<ion-header> <ion-navbar> <button ion-button menuToggle> <ion-icon name="menu"></ion-icon> </button> <ion-title>wiki</ion-title> </ion-navbar> </ion-header> <ion-content padding> <ion-searchbar (ionInput)="getItems($event)" ></ion-searchbar> <ion-list> <ion-item *ngFor="let item of items"> <button ion-button color="dark" clear (click)="itemSelected(tem)">{{ item }}</button> </ion-item> </ion-list> </ion-content>TypeScript:
import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { HomePage } from '../home/home'; @IonicPage() @Component({ selector: 'page-wiki', templateUrl: 'wiki.html', }) export class WikiPage { searchQuery: string = ''; items: string[]; constructor(public navCtrl: NavController, public navParams: NavParams) { this.initializeItems(); } itemSelected(item){ this.navCtrl.push(HomePage); } initializeItems() { this.items = [ 'MSI GTX 1050 GAMING X 2Go', 'Test' ]; } getItems(ev: any) { // Reset items back to all of the items this.initializeItems(); // set val to the value of the searchbar const val = ev.target.value; // if the value is an empty string don't filter the items if (val && val.trim() != '') { this.items = this.items.filter((item) => { return (item.toLowerCase().indexOf(val.toLowerCase()) > -1); }) } } }Thanks for your helping.
Posts: 1
Participants: 1