Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS-在拆卸/清理过滤器时卡住_Angularjs - Fatal编程技术网

AngularJS-在拆卸/清理过滤器时卡住

AngularJS-在拆卸/清理过滤器时卡住,angularjs,Angularjs,我在下拉列表上应用了一个过滤器,但我希望根据另一个下拉列表值将其删除。代码如下。如果用户选择“中”(或任何其他值),那么我需要删除当用户选择“小”时应用的过滤器。现在,如果用户选择“小”然后选择“中”,这些选项仍然会被过滤掉 if(val == "Small"){ $scope.Variant.Specs.Color.Options = $scope.Variant.Specs.Color.Options.filter(function(item) { return item.Value

我在下拉列表上应用了一个过滤器,但我希望根据另一个下拉列表值将其删除。代码如下。如果用户选择“中”(或任何其他值),那么我需要删除当用户选择“小”时应用的过滤器。现在,如果用户选择“小”然后选择“中”,这些选项仍然会被过滤掉

if(val == "Small"){
 $scope.Variant.Specs.Color.Options = $scope.Variant.Specs.Color.Options.filter(function(item) {
  return item.Value !== 'Red' && item.Value !== 'Blue';
 });
}
else if(val == "Medium") {
 $scope.Variant.Specs.Color.Options = $scope.Variant.Specs.Color.Options;
}

创建一个以颜色和大小为参数的角度$过滤器

app.filter('filterColors', function() {
    return function(colors, size) {
        if(size=='Medium') {
            return colors;
        } else {
            return colors.filter(function(d) {
                return d != 'Red' && d != 'Blue';
            });
        }
    }
});

看看这个:我不知道你的问题的答案,但这似乎是你想要的。这非常有用!谢谢!:-)