ngIf depends on a parameter


#1

Hi

I have a list of items with ngIf like the following

<ion-list>
  <ion-item *ngIf="isItemInThisYear(item.id)">  
...
</ion-list>

Each item can appear several times but only the records from this year will appear. This works.

When clicking an item inside this list, I want to reload this page but this time, the list should only show records of the selected item (regardless the date).

I understand that I should change isItemInThisYear to accommodate either options but how can I send the value/parameter from the clicked item to the whole page so it will reload itself with the relevant parameter?


#2

Don’t do this. Set a property inside each item and check that inside the ngIf instead. Function calls inside template expressions that are evaluated during change detection are a performance disaster.


#3

I’m sorry but I’m not sure I understood your answer.

I need that an item click will “reload” the page but this time with a parameter that defines the condition whether to show the item or not. How can I do it by clicking an item? what action should I do in order for the list to reload itself?
Thanks


#4

Simply change a bound property and let Angular’s change detection do the rest. Docs here.


#5

What do you mean by that?


#6

Any kind of help will be appreciated


#7

What’s the point of reloading a page ? You just have to use filter on your array easy peasy… As rapropos told you, using a function in a ngIf is a very bad idea.


#8

Thank you very much, it works