AngularJs将ng-repeat中的item属性传递给controller

时间:2014-04-01 14:15:52

标签: angularjs angularjs-ng-repeat angularjs-controller

我需要将ng-repeat中的item属性传递给控制器​​,如下所示:

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

像这样发送feed.publishedDate不起作用,我应该怎么做?

或者我可以在控制器中访问此属性吗? item.publishedDate没有工作...... 我需要它将它与实际时间进行比较,并按最后一小时,过去4小时过滤新闻,...

$scope.customFilter = function (item, publishedDate) {
    var currentTime = new Date();
    if($scope.timeinterval==1){
             ....
    }

1 个答案:

答案 0 :(得分:1)

过滤函数应返回谓词:

控制器:

$scope.cutoffDate= new Date();

$scope.customFilter = function(cutoffDate) {

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

查看:

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

Fiddle