Angular 使用 OR 运算符过滤

Angular filter with OR operator

我正在尝试从范围滑块构建过滤器。

是否可以设置当我的范围滑块位于其中一个位置时显示多个类别?

通过下面的代码,我可以使用范围进行过滤,但他只对第一个单词进行过滤,在 OR 运算符之后仅此而已。谁能帮帮我?

$scope.filterRange = filterRange;

function filterRange() {
    if (this.rangemodel == 1) {
        $scope.categoryfilter = 'web' || 'ecommerce '; // something like that!
    } else if(this.rangemodel == 2) {
        $scope.categoryfilter = 'branding' || 'video'; // something like that!
    } ;
};

<div ng-repeat="project in projects | filter: {category: categoryfilter}">

我已经在这里看到另一个 post,但仍然不明白如何实现这一点。 =(

感谢丹尼尔,这是可行的解决方案:

$scope.projetos = [];

$scope.filtroRange = filtroRange; 

function filtroRange() {
    if (this.rangemodel == 1) {
        $scope.categoryFilter = function(projeto) {
        if (projeto.categoria === 'site institucional' || projeto.categoria === 'ecommerce') {
            console.log('filtrando');
            return projeto;      
            }
        };
    } else if (this.rangemodel == 2) {
        $scope.categoryFilter = function(projeto) {
        if (projeto.categoria === 'branding' || projeto.categoria === 'email marketing') {
            console.log('filtrando');
            return projeto;      
            }
        };
    }
 };

您可以像这样创建自定义过滤器函数:

$scope.categoryFilter = function(project) {
    if (this.rangemodel == 1) {
        if (project.category === 'web' || project.category === 'ecommerce') {
            return project;      
        }
    } else if (this.rangemodel == 2) {
        if (project.category === 'branding' || project.category === 'video') {
                return project;
            }
        }
    }
};

那么您的 html 将简单地调用此函数作为过滤器:

<div ng-repeat="project in projects | filter: categoryFilter">