Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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_Angularjs Ng Repeat - Fatal编程技术网

Angularjs 不重复的重复

Angularjs 不重复的重复,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,是否有任何“角度方式”可以避免在ng repeat中显示重复项 如果我们在数组中添加重复项,它将弹出[ngRepeat:dupes],这可以通过ng repeat=“item in items track by$index”解决。好 但是,如果我们不想显示副本,该怎么办?我曾想过在创建这样的阵列时进行过滤: if(!$scope.items.indexOf($scope.item ) == -1 ) { $scope.items.push( $scope.item ); } 但是还有其

是否有任何“角度方式”可以避免在
ng repeat
中显示重复项

如果我们在数组中添加重复项,它将弹出
[ngRepeat:dupes]
,这可以通过
ng repeat=“item in items track by$index”
解决。好

但是,如果我们不想显示副本,该怎么办?我曾想过在创建这样的阵列时进行过滤:

if(!$scope.items.indexOf($scope.item ) == -1 ) {
    $scope.items.push( $scope.item );
}

但是还有其他的角度过滤方法吗?

一种角度过滤方法可以是创建一个实现唯一过滤的过滤器

.filter('unique', function() {
    return function (lst) {
       var filteredLst = ...
       ... filtering logic here ...
       return filteredList;
    }
})
然后像这样使用它:

 ng-repeat="item in items | unique"