Przemysław Zamorski Przemysław Zamorski - 2 months ago 8
TypeScript Question

Is it possible to have many cases for ngIF in angular 2 template

i have a list of months number like this:

months = ['1','2','3'...etc]


And i itterate over array in template :

<table *ngFor="let month of allMonthChannel" >
<months *ngIf =" something "></months>
</table>


The question is how i can display my months component when month value only be like 3,6,9,12. What i should i put instead "something " ?
Thanks for answers and sory for my english :)

Answer

A very simple solution could be using modulo, granted you really just need the months 3, 6, 9 and 12:

<table  *ngFor="let month of allMonthChannel"  >
    <months *ngIf="month % 3 == 0"></months> 
</table>

Plunker for a working example