Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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 Filter - Fatal编程技术网

如何在AngularJS中创建过滤器

如何在AngularJS中创建过滤器,angularjs,angularjs-filter,Angularjs,Angularjs Filter,使用AngularJS,如何在数组中创建项的子集 比如,;从“TODO”创建一个新数组,该数组仅包含“done:true”项 请参见10:45左右->结束确定 仅在选中数据的情况下更新变量 您的型号: $scope.todos = [ {text:'foo' , done:false}, {text:'foobar' , done:true}, {text:'foofoo' , done:false},

使用AngularJS,如何在数组中创建项的子集

比如,;从“TODO”创建一个新数组,该数组仅包含“done:true”项

请参见10:45左右->结束

确定

仅在选中数据的情况下更新变量

您的型号:

$scope.todos = [
        {text:'foo'        , done:false}, 
        {text:'foobar'     , done:true},
        {text:'foofoo'     , done:false}, 
        {text:'foobar2'    , done:true}
 ]
您只需要检查:

$scope.todoselect = $filter('filter')($scope.todos, {done:true});
当模型更改时,您希望更新变量,所以请使用控制器中的“监视”

$scope.$watch('todos', function(newval, oldval){
                        if (oldval != newval)
                        {   
                      $scope.todoselect = $filter('filter')($scope.todos, {done: true});
                            }
                            },true
                        );
  });

示例:

只需将过滤器添加到您的ngRepeat中,并仅显示所需内容:

ng-repeat='todo in todos | filter:done==true'
小提琴:

如果要从列表中完全删除该元素,请使用FIDLE中的
archive
功能

注意:从版本1.1.3开始,过滤器行为已更改。您现在需要使用

ng-repeat='todo in todos | filter:{done:true}'

Fiddle:

好的,我在中创建了一个示例。我最终实现了这一点。谢谢你的帮助。
ng-repeat='todo in todos | filter:{done:true}'