Search code examples
ruby-on-railsrubyangularjsng-show

angular ng-show greater than is not evaluating


I've been trying for two days to make date filters with input using Rails and angular, but finally I gave up. The format of the date that the input is giving to me is different than the one that I need, and I can't change it.

I think I can do the "filters" in an alternative easiest way. I realized that using ruby I can obtain the dates in the format I need very easy, so I am trying to show and hide the elements comparing the ruby date with the date of the element.

So I am trying this:

<section ng-repeat="event in events | orderBy:'date' | filter:myFilter" 
         ng-show="(<%= Date.today.to_s  %> <= {{event.date}})">

but the expression ng-show="(<%= Date.today.to_s %>) <= ({{event.date}})" is not evaluating or is always true, because it is showing all the events, including the previous to the date.

I also tried "(<%= Date.today.to_s %> <= event.date)" but this one is always false, so all the elements are hidden...

Somebody can help me?

Edit: the myFilter is set in a similar way to only show today's events, and is working.

<a id="filter-by-date" class="btn btn-success wide-btn" href="#" 
   ng-click="myFilter = '<%= Date.today.to_s  %>'">Today Events</a>

Solution

  • Move the math inside the controller

    HTML

    <section ng-repeat="event in events | orderBy:'date' | filter:myFilter" 
         ng-show="computeShow(event.date)">
    

    JS

    $scope.computeShow = function (eventDate) {
        return (
            //compute eventDate >= today's date
        )
    };