Home Web Front-end JS Tutorial Example code sharing on how angularJs uses $watch and $filter to create search filters.

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

Jun 01, 2017 am 09:12 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Users encounter rare glitches: Samsung Watch smartwatches suddenly experience white screen issues Users encounter rare glitches: Samsung Watch smartwatches suddenly experience white screen issues Apr 03, 2024 am 08:13 AM

You may have encountered the problem of green lines appearing on the screen of your smartphone. Even if you have never seen it, you must have seen related pictures on the Internet. So, have you ever encountered a situation where the smart watch screen turns white? On April 2, CNMO learned from foreign media that a Reddit user shared a picture on the social platform, showing the screen of the Samsung Watch series smart watches turning white. The user wrote: "I was charging when I left, and when I came back, it was like this. I tried to restart, but the screen was still like this during the restart process." Samsung Watch smart watch screen turned white. The Reddit user did not specify the smart watch. Specific model. However, judging from the picture, it should be Samsung Watch5. Previously, another Reddit user also reported

How vue3 data monitors watch/watchEffect How vue3 data monitors watch/watchEffect May 12, 2023 pm 06:31 PM

We all know that the function of the listener is to trigger every time the reactive state changes. In the combined API, we can use the watch() function and watchEffect() function. When you change the reactive state, it may be triggered at the same time. Trigger Vue component updates and listener callbacks. By default, user-created listener callbacks will be called before the Vue component is updated. This means that the DOM you access in the listener callback will be the state it was in before it was updated by Vue. So, let’s take a look, how can we make good use of them? What's the difference between them? The watch() function watch needs to listen to a specific data source, such as listening to a ref. The first parameter of watch can be

How to use watch in Vue to monitor changes in an array How to use watch in Vue to monitor changes in an array Jun 11, 2023 am 10:54 AM

How to use watch in Vue to monitor array changes. Vue is one of the most widely used frameworks in front-end development. It provides many convenient ways to implement functions such as data responsiveness, template rendering, and componentization. In Vue, we often use watch to monitor data changes. However, when we need to monitor array changes, we need to pay attention to some details. In Vue, we can use watch to monitor changes in a single property or object. The basic usage is as follows: watch:{

How to open Control Center on Apple Watch in watchOS 10 How to open Control Center on Apple Watch in watchOS 10 Sep 20, 2023 pm 02:17 PM

How to Access Control Center in watchOS 10 The way we interact with our watches has remained more or less the same since Apple launched the first Apple Watch. Even after adding so many new features, the overall user interface remains consistent. But watchOS10 brings big changes! On an Apple Watch running watchOS 9 or earlier, you can quickly open Control Center by swiping up on the screen. However, with the update to watchOS 10, the swipe-up gesture pulls up a whole new smart stack of widgets instead of Control Center. So the big question is how to open the Control Center on Apple Watch in WatchOS10. The answer is as follows:

How to solve the '[Vue warn]: Failed to resolve filter' error How to solve the '[Vue warn]: Failed to resolve filter' error Aug 19, 2023 pm 03:33 PM

Methods to solve the "[Vuewarn]:Failedtoresolvefilter" error During the development process using Vue, we sometimes encounter an error message: "[Vuewarn]:Failedtoresolvefilter". This error message usually occurs when we use an undefined filter in the template. This article explains how to resolve this error and gives corresponding code examples. When we are in Vue

The latest 5 angularjs tutorials in 2022, from entry to mastery The latest 5 angularjs tutorials in 2022, from entry to mastery Jun 15, 2017 pm 05:50 PM

Javascript is a very unique language. It is unique in terms of the organization of the code, the programming paradigm of the code, and the object-oriented theory. The issue of whether Javascript is an object-oriented language that has been debated for a long time has obviously been There is an answer. However, even though Javascript has been dominant for twenty years, if you want to understand popular frameworks such as jQuery, Angularjs, and even React, just watch the "Black Horse Cloud Classroom JavaScript Advanced Framework Design Video Tutorial".

Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Jun 27, 2023 pm 07:37 PM

In today's information age, websites have become an important tool for people to obtain information and communicate. A responsive website can adapt to various devices and provide users with a high-quality experience, which has become a hot spot in modern website development. This article will introduce how to use PHP and AngularJS to build a responsive website to provide a high-quality user experience. Introduction to PHP PHP is an open source server-side programming language ideal for web development. PHP has many advantages, such as easy to learn, cross-platform, rich tool library, development efficiency

What is the implementation principle of Vue3 listener watch What is the implementation principle of Vue3 listener watch Jun 04, 2023 pm 02:05 PM

The essence of watch The essence of watch is to observe a responsive data and notify and execute the corresponding callback function when the data changes. In fact, the essence of watch implementation is to use the effect and options.scheduler options. As shown in the following example: //The watch function receives two parameters, source is the responsive data, and cb is the callback function functionwatch(source,cb){effect(//Trigger the read operation to establish the connection ()=>source.foo ,{scheduler(){//When the data changes, call the callback function cbcb()}})} as shown in the above code

See all articles