时间:2021-05-30 08:45:05 | 栏目:AngularJS | 点击:次
如下所示:
<div ng-app="module" ng-controller="ctrl"> <table border="1" width="600"> <tr> <td>编号</td> <td>姓名</td> <td>手机号</td> </tr> <tr ng-repeat="(k,v) in data"> <td>{{v.id}}</td> <td>{{v.name}}</td> <td>{{v.mobile|truncate:4}}</td> </tr> </table> </div> <script> var m = angular.module('module', []); /*自定义过滤器truncate*/ m.filter('truncate',function(){ return function(mobile,len){ len = len?len:3; return mobile.substr(0,11-len)+new String('*').repeat(len); } }); m.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) { $scope.data = [ {id: 1, name: '张三', mobile: '14567654445'}, {id: 2, name: '李四', mobile: '13910959565'}, {id: 3, name: '王五', mobile: '13232343425'}, ]; }]); </script>
效果图: