AngularJS filtering between a range

后端 未结 1 2004
粉色の甜心
粉色の甜心 2020-12-17 02:11

I have set up a range slider that ranges from 0 - 2hr, the times are calculated in mins then converted to hh:mm like this: 10min, 20min, 1hr 20min, 2hr.

But now I am

1条回答
  •  青春惊慌失措
    2020-12-17 02:44

    Pass the sliderConfig into the filter to find the current min and max set on the range slider. Make sure your objects are in an array.

        
    ... // Pass the slider config into the filter
    {{ time.time | customFilter}}
    ... $scope.times = [ {time: '20'}, {time: '50'}, ... ];

    The rangeFilter has the second parameter 'rangeInfo' which we can get the 2 values from.

    app.filter('rangeFilter', function() {
        return function( items, rangeInfo ) {
            var filtered = [];
            var min = parseInt(rangeInfo.userMin);
            var max = parseInt(rangeInfo.userMax);
            // If time is with the range
            angular.forEach(items, function(item) {
                if( item.time >= min && item.time <= max ) {
                    filtered.push(item);
                }
            });
            return filtered;
        };
    });
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题