2016-09-27 17 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。我很傻:第 –

相關問題