# Ion search show list when start typing

**URL:** <https://forum.ionicframework.com/t/ion-search-show-list-when-start-typing/133357>\
**Category:** ionic-v3\
**Created:** [June 22, 2018, 9:13am UTC](https://forum.ionicframework.com/t/ion-search-show-list-when-start-typing/133357 "2018-06-22T09:13:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [June 22, 2018, 9:13am UTC](https://forum.ionicframework.com/t/ion-search-show-list-when-start-typing/133357/1 "2018-06-22T09:13:47Z")

</div>

Hi all,  
I have a list and when I search items the list shrinks when start typing a letter. What I want is to hide the list until a user starts typing. What can I do to do that. I know I have to change something and have to insert an if… But where?

```auto
// Selectie op toetsaanslagen
	getItems(searchbar) {
  // Reset items back to all of the items
  this.initializeItems();

  // set q to the value of the searchbar
  var q = searchbar.srcElement.value;

  // if the value is an empty string don't filter the items
  if (!q) {
    return;
  }

  this.productList = this.productList.filter((v) => {
    if(v.name && q) {
      if (v.name.toLowerCase().indexOf(q.toLowerCase()) > -1) {
        return true;
      }
      return false;
    }
  });

  console.log(q, this.productList.length);

}
//Einde selectie op toetsaanslagen

```

---

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [June 22, 2018, 10:28am UTC](https://forum.ionicframework.com/t/ion-search-show-list-when-start-typing/133357/2 "2018-06-22T10:28:10Z")

</div>

I forgot something, this is the piece where I have to change something I guess:

```auto
this.productRef = firebase.database().ref('/products');
		this.productRef.on('value', productList => {
  let products = [];
  productList.forEach( product => {
    products.push(product.val());
    return false;
  });

  this.productList = products;
  this.loadedProductList = products;
});

```

---

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [June 22, 2018, 2:06pm UTC](https://forum.ionicframework.com/t/ion-search-show-list-when-start-typing/133357/3 "2018-06-22T14:06:13Z")

</div>

Found the solution 🙂

under export class:

```auto
showList: boolean = false;
	searchQuery: string = '';

```

Then under constructor:

```auto
initializeItems(): void {
  this.productList = this.loadedProductList;
}

// Selectie op toetsaanslagen
	getItems(searchbar) {
  // Reset items back to all of the items
  this.initializeItems();

  // set q to the value of the searchbar
  var q = searchbar.srcElement.value;

  // if the value is an empty string don't filter the items
  if (q && q.trim() != '') {
    

  this.productList = this.productList.filter((v) => {
    
      return (v.name.toLowerCase().indexOf(q.toLowerCase()) > -1);
	});
	
	// Show the results
      this.showList = true;
    } else {
      
      // hide the results when the query is empty
      this.showList = false;
											 }
  console.log(q, this.productList.length);
	
}

```

And on the html page in the ion-list:

```auto
*ngIf="showList"

```

If anyone needs help with this 😉 Than I can help with all parts.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:31pm UTC](https://forum.ionicframework.com/t/ion-search-show-list-when-start-typing/133357/4 "2021-07-19T21:31:50Z")

</div>

Closed on July 19, 2021, 9:31pm UTC


