Angular过滤器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../angular-1.5.5/angular.min.js"></script>
    <script>
        angular.module("myapp", [])
        //过滤
            .filter("doFilter", function () {
                return function (arr, flag) {
                    var arrs = [];
                    for (var i = 0; i < arr.length; i++) {
                        if (arr[i].done == false) {
                            arrs.push(arr[i])
                        } else {
                            if (flag == true) {
                                arrs.push(arr[i])
                            }
                        }
                    }
                    return arrs;
                }
            })
            .controller("myCtrl", function ($scope) {
                $scope.arr = [{
                    schedule: "约刘诗诗去吃饭", done: false
                }, {
                    schedule: "约刘诗诗去长城", done: false
                }, {
                    schedule: "约刘诗诗看电影", done: true
                }]
                //添加
                $scope.add = function () {
                    $scope.arr.push({schedule: $scope.affair, done: false});
                    $scope.affair = "";
                }
            })

    </script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<h1>约刘诗诗吃饭</h1>
<input type="text" ng-model="affair">
<button ng-click="add()">添加</button>
<table>
    <tr>
        <th>序号</th>
        <th>日程</th>
        <th>完成情况</th>
    </tr>
    <tr ng-repeat="item in arr|doFilter:complate">
        <td>{{$index}}</td>
        <td>{{item.schedule}}</td>
        <td><input type="checkbox" ng-model="item.done"></td>
    </tr>
</table>
显示全部 <input type="checkbox" ng-model="complate">
</body>
</html>
原文地址:https://www.cnblogs.com/yu12/p/7570921.html