Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs自定义过滤器大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html>
<html>
<head>
    <Meta charset="utf-8" />
    <title>angularjs自定义过滤器</title>
    <link rel="stylesheet" href="bootstrap.min.css" />
    <script src="jquery-2.1.3.min.js"></script>
    <script src="bootstrap.min.js"></script>
    <script src="angular.min.js"></script>
</head>
<body ng-app="Demo" ng-controller="TESTCtrl">
关键字:<input ng-model="key">
<table class="table table-bordered">
    <tr>
        <td ng-click="orderBy('id')" style="cursor: pointer">序号</td>
        <td ng-click="orderBy('name')" style="cursor: pointer">名字</td>
        <td ng-click="orderBy('phone')" style="cursor: pointer">邮箱</td>
    </tr>
    <tr ng-repeat="item in lists">
        <td>{{item.iD}}</td>
        <td>{{item.namE}}</td>
        <td>{{item.phone |trunct:4}}</td>
    </tr>
</table>
<script type="text/javascript">
    (function(){
        var app = angular.module('Demo',["ngAnimate"])
            .controller('TESTCtrl',TESTCtrl);

        app.filter('trunct',function () {
            return function (mobile,len) {
                mobile = mobile.substr(0,(11 -len)) + new String("*").repeat(len);
                return mobile;
            }
        });

        function TESTCtrl($scope,$filter) {
            $scope.items = [
                { id: "1",name : "小白牛",phone : "13465352119" },{ id: "2",name : "迷迭香",phone : "1565354662" },{ id: "3",name : "龙之谷",phone : "19765354891" },];

            $scope.status = {id:false,name: false,phone :falsE};
            $scope.lists = angular.copy($scope.items);
            $scope.orderBy = function (item) {
                $scope.status[item] = !$scope.status[item];
                $scope.lists = $filter('orderBy')($scope.lists,item,$scope.status[item]);
            };
            $scope.lists = $scope.items;
            $scope.$watch('key',function (n,w) {
                $scope.lists = $filter('filter')($scope.items,n);
            });
        }
    }());


</script>
</body>
</html>

大佬总结

以上是大佬教程为你收集整理的angularjs自定义过滤器全部内容,希望文章能够帮你解决angularjs自定义过滤器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。