Date with filter in angularJs

时间:2015-05-12 23:08:47

标签: angularjs date angularjs-ng-repeat angular-ng-if

I'm trying to select objects within an String TWITTER="EEE MMM dd HH:mm:ss ZZZZZ yyyy"; SimpleDateFormat sf = new SimpleDateFormat(TWITTER,Locale.ENGLISH); , using ng-repeat

ng-if= "condition == {{date | date:"M"}}" works in my Angular page, returning "5"; but does not seem to work within my {{date | date:"M"}}. Could anyone point me in the right direction?

Here is the non working code:

ng-if

And this is a working example, when I replace the <li ng-repeat="task in tasks" ng-if="task.month == {{date | date:"M"}} || task.month == 0"> <a href="#/task/{{task.id}}"><h2>{{task.title}}</h2></a> </li> with a "5";

{{date}}

1 个答案:

答案 0 :(得分:0)

ng-if需要一个Javascript表达式,{{ }}括号不是有效的Javascript。如您所示,括号可以在href和其他地方使用,但不能在ng-if中使用。

相反,请在表达式中使用Javascript&#39; date.getMonth()

<li ng-repeat="task in tasks" ng-if="task.month == date.getMonth() || task.month == 0">