1

I need to pass an item property in an ng-repeat to the controller like this:

<li ng-repeat="feed in feeds | filter:customFilter(feed,feed.publishedDate) "> 

Sending feed.publishedDate like this does't work, how should I do that?

Or could I access this property in the controller? item.publishedDate doesn;t work... I need it to compare it with the actual time and filter the news by last hour, last 4 hours, ...

$scope.customFilter = function (item, publishedDate) {
    var currentTime = new Date();
    if($scope.timeinterval==1){
             ....
    }
4
  • That's not how you use filters in views, it should be: <li ng-repeat="feed in feeds | customFilter: feed, feed.publishedDate "> Not sure if this solves your parameter problem though... Commented Apr 1, 2014 at 14:24
  • No.. but thanks! My filter is in a controller Commented Apr 1, 2014 at 14:33
  • Why not write a .filter() module? Commented Apr 1, 2014 at 14:37
  • I would still have the same problem, I need a property of each element in the ng-repeat (feed.publishedDate) Commented Apr 1, 2014 at 14:39

1 Answer 1

1

The filter function should return a predicate:

Controller:

$scope.cutoffDate= new Date();

$scope.customFilter = function(cutoffDate) {

    return function(feed){
        return feed.publishedDate <= cutoffDate;
    };
};

View:

ng-repeat="feed in feeds | filter:customFilter(cutoffDate)" 

Fiddle

Sign up to request clarification or add additional context in comments.

9 Comments

The problem is check that condition, for that I need the publishedDate that is in feed.publishedDate, and filter:customFilter(feed.publishedDate) doen't work
The feed is passed to the predicate so you can check it there. I'll amend the example.
That was my first idea, but feed.publishedDate doesn't work :S
item.publishedDate <= new Date(); or item.publishedDate >= new Date(); is always false
if (item.publishedDate) always false too
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.