Przemysław Zamorski Przemysław Zamorski - 1 year ago 63
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>

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 Source

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> 

Plunker for a working example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download