Search code examples
javascriptangularjsdatehamlangular-filters

Cannot get filter to execute in AngularJS


I have an ng-repeat of events, each of which has a date. I want to allow the user to filter out all events not between two dates. I figured I'd make a custom filter for this.

I'm using HAML, so here's how my HTML looks:

%tr{'ng-repeat' => 'event in events | filter:dateRange | event.name'}

Okay so now my filter looks like this right now:

filters.filter('dateRange', function() {
  return function(){
    var a = 'a';
    return a;
  };
});

Obviously my filter doesn't really do anything yet, but when I set a breakpoint on var a, or on return a, it never is reached. I want to do this so I can see the context at this point and then write the filter. I know it reaches the filter because when I set a breakpoint on filters.filter, it does reach it. Why does it not enter the function and execute anything?


Solution

  • The ng-repeat value should look like

    %tr{'ng-repeat' => 'event in events | dateRange: event.name'}
    

    when using a filter you supply the filter name, and optionally if you have arguments to your filter you follow with a colon and then the expression.