TypeError: format.match is not a function in moment angularJS

点点圈 提交于 2019-12-12 05:38:27

问题


Hi I am trying to compare today's date with ng-repeat date field using momentJS

here is my html code

<span class="time-stamp float-right" ng-if="recent.createdAt | amDateFormat: 'DD/MM/YYYY' == todayDate">{{ recent.createdAt | amDateFormat: 'hh:mm A' }}</span>
        <span class="time-stamp float-right" ng-if="recent.createdAt | amDateFormat: 'DD/MM/YYYY' != todayDate">{{ recent.createdAt | amDateFormat: 'DD/MM/YYYY' }}</span>

and here is today's variable I declared

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()

if(day<10)
{
    day = '0' + day;
}
if(month<10)
{
  month = '0' + month;
}
$scope.todayDate = (day + "/" + month + "/" + year);

but when I compare it gives me error of TypeError: format.match is not a function any help please that how to compare with today's date

EDIT - {{ recent.createdAt | amDateFormat: 'DD/MM/YYYY' }} gives perfect result as 08/04/2016 like this


回答1:


Since the binding syntax is evaluating an expression: Add () to date/filter: {{ (recent.createdAt | amDateFormat: 'DD/MM/YYYY') == todayDate }}



来源:https://stackoverflow.com/questions/36513967/typeerror-format-match-is-not-a-function-in-moment-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!