I am currently working on implementing a single search bar that can filter lists in 2 different tabs within Ionic 2. The search bar is functional, and I have a method for filtering through objects. However, my goal is to allow users to select different tabs to specify what they want to search for. For instance, the "Search Page" includes an ion-searchbar and ion-tabs with 2 options - People and Blogs. When a user inputs content into the search bar, it should filter results based on the active tab. By default, the page displays results for people, but users can click on the blogs tab to switch their search focus. Currently, this is how the SearchPage looks like:
<ion-header text-center>
<ion-navbar>
<ion-title>Search Page</ion-title>
</ion-navbar>
<ion-header>
<ion-searchbar [(ngModel)]="searchTerm" [formControl]="searchControl" (ionInput)="onSearchInput()"></ion-searchbar>
<div *ngIf="searching" class="spinner-container">
<ion-spinner></ion-spinner>
</div>
<ion-tabs tabsPlacement="top">
<ion-tab tabIcon="people" [root]="peopleSearch"></ion-tab>
<ion-tab tabIcon="pricetags" [root]="postsSearch"></ion-tab>
</ion-tabs>
Placing the search bar in the main section ensures that it remains constant while switching between tabs without needing to refresh or redraw. However, I'm facing challenges accessing its value and event listeners on both tab pages. Currently, I can only utilize them on the main page. I'm considering using @ViewChild to address this issue, but I lack the expertise in Ionic to implement it effectively across both tabbed pages. Any guidance would be greatly appreciated. Thank you.
Here's a tutorial where I sourced some of my code: Link