Home > Web Front-end > JS Tutorial > angluarjs filter and replace keyword function implementation code

angluarjs filter and replace keyword function implementation code

小云云
Release: 2018-02-08 11:29:35
Original
1417 people have browsed it

This article mainly introduces to you in detail the small functions of angluarjs to filter and replace keywords. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

html style


<body ng-app="myapp" ng-controller="myCtrl">
   <input type="text" ng-model="keytext">
   <p>{{ keytext|wordFilter:"#" }}</p>
</body>
Copy after login

//Customize the filter and replace the keyword


<script>
    var myapp=angular.module("myapp",[]);
    /*自定义过滤器*/
    myapp.filter("wordFilter",function () {
      return function (msg,flag) {
        /*替换关键字*/
        return msg.replace(/枪|子弹/g,flag);
      }
    })
    myapp.controller("myCtrl",function ($scope) {
      $scope.keytext="";
    })
  </script>
Copy after login

The effect is as follows:

Related recommendations:

Angularjs filter completes the sorting function example detailed explanation

How to use jQuery sub-element filter selector

Angular search filter batch delete some function summary

The above is the detailed content of angluarjs filter and replace keyword function implementation code. 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