2016-09-27 40 views
0

我有这样的月数列表:是否有可能有很多情况下ngIF在角2模板

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

而且我itterate在数组中的模板:

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

问题是如何我可以显示我的月份组件时,月份值只有像3,6,9,12。我应该把什么,而不是“东西”? 感谢答案和索里,我的英语:)

+1

您是在寻找https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html? –

回答

3

一个非常简单的解决办法是使用modulo,授予你真的只需要3个月,6,9和12:

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

Plunker为一个工作示例

+1

尽管你已经明确给出了他要求的答案,但我认为提及NgSwitch指令对任何发现此问题的人都有用,它将寻找一个无法用简单的数学方法解决的问题。 – gelliott181

+1

你说得对,以后我会这样做的! :) – rinukkusu

+1

正常工作。即时通讯新的角2和打字稿,我没有想出,我可以使用简单的数学角2。我很傻:第 –

相关问题