Angularjs 获取当前过滤元素的索引(以角度为单位)

Angularjs 获取当前过滤元素的索引(以角度为单位),angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我有一个自定义函数用作过滤器。如何获得筛选的当前元素的索引 <tr ng-repeat="(idx, line) in items | filter:inRange">....</tr> //this is the filter $scope.inRange = function(item) { //how to get the index here? }; 如 筛选器不处理数组中的单个项,而是将整个数组转换为另一个数组 当定义为筛选器时,inRange将接收

我有一个自定义函数用作过滤器。如何获得筛选的当前元素的索引

<tr ng-repeat="(idx, line) in items | filter:inRange">....</tr>

//this is the filter
$scope.inRange = function(item) {
    //how to get the index here?
};

筛选器不处理数组中的单个项,而是将整个数组转换为另一个数组

当定义为筛选器时,
inRange
将接收整个
数组,而不是单个项

myModule.filter('inRange', function() {
    return function(items) {
        var filtered = [];
        angular.forEach(items, function(item, index) {
            // do whatever you want here with the index
            filtered.push(item);
        });
        return filtered;
    }
});

是的,对于在阵列上运行的筛选器,您所说的是正确的。
我不想使用indexOf
不清楚您期望的是什么
myModule.filter('inRange', function() {
    return function(items) {
        var filtered = [];
        angular.forEach(items, function(item, index) {
            // do whatever you want here with the index
            filtered.push(item);
        });
        return filtered;
    }
});