# Hiding (and showing) list items in ionic

**URL:** <https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920>\
**Category:** ionic-v3\
**Created:** [March 19, 2016, 10:12pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920 "2016-03-19T22:12:18Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![max\_maeuschen](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@max\_maeuschen](https://forum.ionicframework.com/u/max_maeuschen)\
**Post date:** [March 19, 2016, 10:12pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/1 "2016-03-19T22:12:18Z")

</div>

Is it possible inside ion-list to hide an item in ionic 2? I tried the same way as in ionic 1 using ng-show, but it doesn’t work.

---

<div class="post-metadata">

**Author:** ![xr0master](https://avatars.discourse-cdn.com/v4/letter/x/b4bc9f/32.png) [@xr0master](https://forum.ionicframework.com/u/xr0master)\
**Post date:** [March 19, 2016, 10:45pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/2 "2016-03-19T22:45:07Z")

</div>

use \*ngIf instead of ng-show  
or [style.display]=""

---

<div class="post-metadata">

**Author:** ![max\_maeuschen](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@max\_maeuschen](https://forum.ionicframework.com/u/max_maeuschen)\
**Post date:** [March 20, 2016, 8:11am UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/3 "2016-03-20T08:11:20Z")

</div>

I tried this without success. Here’s my code:

```
<ion-list>
   <ion-item-sliding *ngFor="#item of items" #slidingItem>
     <ion-item *ngIf="item.deleted === false">{{item.name}} </ion-item>
     <ion-item-options>
       <button (click)="showEditModal(item, slidingItem)"><ion-icon name="create"></ion-icon>Bearbeiten</button>
       <button danger (click)="doConfirm(item, slidingItem)"><ion-icon name="trash"></ion-icon>Löschen</button>
     </ion-item-options>
   </ion-item-sliding>
 </ion-list>

```

I can’t see where the error is. Can you help me? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![beck24](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/beck24/32/112174_2.png) [@beck24](https://forum.ionicframework.com/u/beck24)\
**Post date:** [March 20, 2016, 8:31am UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/4 "2016-03-20T08:31:30Z")

</div>

I don’t see any issue with that. Are you sure item.deleted === false on the ones you don’t want to show? Perhaps it’s a falsey item.deleted = 0 instead?

---

<div class="post-metadata">

**Author:** ![xr0master](https://avatars.discourse-cdn.com/v4/letter/x/b4bc9f/32.png) [@xr0master](https://forum.ionicframework.com/u/xr0master)\
**Post date:** [March 20, 2016, 8:34am UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/5 "2016-03-20T08:34:22Z")

</div>

Your code looks fine. Are you sure that the item.deleted is false?

---

<div class="post-metadata">

**Author:** ![max\_maeuschen](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@max\_maeuschen](https://forum.ionicframework.com/u/max_maeuschen)\
**Post date:** [March 20, 2016, 7:13pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/6 "2016-03-20T19:13:01Z")

</div>

If \*ngIf=“item.deleted === false” is there, there are no items shown in the list. But they are all shown, if \*ngIf=“item.deleted === false” is remove.

The problem isn’t the value of item.deleted. If {{item.deleted}} is inserted in ion-item, the values are shown as wanted.

---

<div class="post-metadata">

**Author:** ![xr0master](https://avatars.discourse-cdn.com/v4/letter/x/b4bc9f/32.png) [@xr0master](https://forum.ionicframework.com/u/xr0master)\
**Post date:** [March 20, 2016, 8:21pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/7 "2016-03-20T20:21:35Z")

</div>

99% your issue in the condition. Try use this code:

> \*ngIf="!item.deleted’

---

<div class="post-metadata">

**Author:** ![max\_maeuschen](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@max\_maeuschen](https://forum.ionicframework.com/u/max_maeuschen)\
**Post date:** [March 20, 2016, 9:24pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/8 "2016-03-20T21:24:53Z")

</div>

Thank you for your suggestion, but I tried this before without success.

At the moment I had some success by the following code:

```
<ion-list *ngFor="#item of items">
  <ion-item-sliding *ngIf="item.deleted === false" #slidingItem>
    <ion-item>{{item.fach}} ({{item.kuerzel}})</ion-item>
    <ion-item-options>
      <button (click)="showEditModal(item, slidingItem)"><ion-icon name="create"></ion-icon>Bearbeiten</button>
      <button danger (click)="doConfirm(item, slidingItem)"><ion-icon name="trash"></ion-icon>Löschen</button>
    </ion-item-options>
  </ion-item-sliding>
</ion-list>

```

Now the items with item.deleted === true are not shown anymore, but there’s an empty line after each item.

---

<div class="post-metadata">

**Author:** ![iignatov](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iignatov/32/100112_2.png) [@iignatov](https://forum.ionicframework.com/u/iignatov)\
**Post date:** [March 20, 2016, 9:41pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/9 "2016-03-20T21:41:17Z")

</div>

I would suggest you to filter the items in the class instead of doing it in the template:

```auto
<!-- template -->
<ion-list>
  <ion-item-sliding *ngFor="#item of getActiveItems()" #slidingItem>
    <ion-item>{{item.fach}} ({{item.kuerzel}})</ion-item>
    <ion-item-options>
      <button (click)="showEditModal(item, slidingItem)"><ion-icon name="create"></ion-icon>Bearbeiten</button>
      <button danger (click)="doConfirm(item, slidingItem)"><ion-icon name="trash"></ion-icon>Löschen</button>
    </ion-item-options>
  </ion-item-sliding>
</ion-list>

```

```auto
@Page(
    // ...
)
export class TestPage {
    // ...
    getActiveItems() {
        // NOTE: Returning a new array might mess up the change detection of Ng2.
        // TODO: Use an existing array instead of returning a new one each time.
        return this.items.filter(item => !item.deleted);
    }
}

```

---

<div class="post-metadata">

**Author:** ![iignatov](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iignatov/32/100112_2.png) [@iignatov](https://forum.ionicframework.com/u/iignatov)\
**Post date:** [March 20, 2016, 10:31pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/10 "2016-03-20T22:31:53Z")

</div>

Just in case that you prefer to do the filtering in the template then you can do it this way:

```auto
<ion-list>
  <template ngFor #item="$implicit" [ngForOf]="items">
    <ion-item-sliding *ngIf="!item.deleted" #slidingItem>
      <ion-item>{{item.fach}} ({{item.kuerzel}})</ion-item>
      <ion-item-options>
        <button (click)="showEditModal(item, slidingItem)"><ion-icon name="create"></ion-icon>Bearbeiten</button>
        <button danger (click)="doConfirm(item, slidingItem)"><ion-icon name="trash"></ion-icon>Löschen</button>
      </ion-item-options>
    </ion-item-sliding>
  </template>
</ion-list>

```

---

<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:** [March 21, 2016, 9:52pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/11 "2016-03-21T21:52:42Z")

</div>

Just want to chime in on this.

If you want to dynamically hide/show elements, you can use the DOMs api for this.

```auto
  <ion-card [hidden]="shouldHide">
    <ion-card-header>
      Card Header
    </ion-card-header>
    <ion-card-content>
      Hello World
    </ion-card-content>
  </ion-card>

```

And then somewhere in the class, `shouldHide` is a true/false value.

---

<div class="post-metadata">

**Author:** ![max\_maeuschen](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@max\_maeuschen](https://forum.ionicframework.com/u/max_maeuschen)\
**Post date:** [March 21, 2016, 10:43pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/12 "2016-03-21T22:43:18Z")

</div>

Thank you for your replies. At the moment I use the possibility with getActiveItems(), which was the first one, that works for me.

---

<div class="post-metadata">

**Author:** ![anrus](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anrus](https://forum.ionicframework.com/u/anrus)\
**Post date:** [February 23, 2017, 10:13am UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/13 "2017-02-23T10:13:13Z")

</div>

`<ion-card [hidden]="!flag">`  
It worked for me

---

<div class="post-metadata">

**Author:** ![rsa](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@rsa](https://forum.ionicframework.com/u/rsa)\
**Post date:** [April 28, 2017, 10:51am UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/14 "2017-04-28T10:51:29Z")

</div>

Hi @mhartington, you saved my time. tnx

---

<div class="post-metadata">

**Author:** ![gregv21v](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@gregv21v](https://forum.ionicframework.com/u/gregv21v)\
**Post date:** [June 15, 2017, 10:52pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/15 "2017-06-15T22:52:28Z")

</div>

Where is the documentation for `<template>`?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 15, 2017, 11:08pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/16 "2017-06-15T23:08:34Z")

</div>

That’s a bit of a confusing question, because the post you’re replying to doesn’t include that element (although it does exist). Probably the best resource on the general topic is [here](https://angular.io/guide/template-syntax).

---

<div class="post-metadata">

**Author:** ![gregv21v](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@gregv21v](https://forum.ionicframework.com/u/gregv21v)\
**Post date:** [June 15, 2017, 11:17pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/17 "2017-06-15T23:17:42Z")

</div>

This is what I am referring to: `<template ngFor #item="$implicit" [ngForOf]="items">`

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 15, 2017, 11:21pm UTC](https://forum.ionicframework.com/t/hiding-and-showing-list-items-in-ionic/46920/18 "2017-06-15T23:21:55Z")

</div>

My bad, I was somehow looking at the previous post that had it in a `<!-- template -->` comment.

The `<template>` element has been deprecated as of Angular 4, so you should look at [the documentation for ng-template](https://angular.io/guide/structural-directives#the-ng-template) instead.
