Home >Web Front-end >JS Tutorial >Example code sharing on how angularJs uses $watch and $filter to create search filters.
This article mainly introduces angularJsUsing $watch and $filterFilterProductionSearchFiltering examples, with certain For reference value, interested friends can refer to the
organization document, search out an angularJs using $watch and $filter filters to create search filters, and organize and streamline it a little for sharing.
<p ng-app="module" ng-controller="ctrl"> 搜索: <input type="text" ng-model="search"> <table border="1" width="600"> <tr> <td>编号</td> <td>点击数</td> <td>标题</td> </tr> <tr ng-repeat="(k,v) in lists"> <td>{{v.id}}</td> <td>{{v.click}}</td> <td>{{v.title}}</td> </tr> </table> </p> <script> var m = angular.module('module', []); m.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) { $scope.data = [ {id: 1, click: 100, title: '百度'}, {id: 2, click: 200, title: '腾讯'}, {id: 3, click: 300, title: '谷歌'}, ]; //临时数据用于显示 $scope.lists = $scope.data; $scope.$watch('search',function(n,o){ $scope.lists = $filter('filter')($scope.data,n); }); }]); </script>
Rendering:
The above is the detailed content of Example code sharing on how angularJs uses $watch and $filter to create search filters.. For more information, please follow other related articles on the PHP Chinese website!