Home > Web Front-end > JS Tutorial > body text

Example code sharing on how angularJs uses $watch and $filter to create search filters.

黄舟
Release: 2017-06-01 09:12:43
Original
1558 people have browsed it

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(&#39;module&#39;, []);
  m.controller(&#39;ctrl&#39;, [&#39;$scope&#39;, &#39;$filter&#39;, function ($scope, $filter) {
    $scope.data = [
      {id: 1, click: 100, title: &#39;百度&#39;},
      {id: 2, click: 200, title: &#39;腾讯&#39;},
      {id: 3, click: 300, title: &#39;谷歌&#39;},
    ];
    //临时数据用于显示
    $scope.lists = $scope.data;
    $scope.$watch(&#39;search&#39;,function(n,o){
      $scope.lists = $filter(&#39;filter&#39;)($scope.data,n);
    });
  }]);
</script>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!