We can create our own custom filter depending on our own requirement. Here I will show one of the simple and interesting custom filters in below example
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <script src="../Scripts/angular.js"></script> <script> var app = angular.module("MyApp", []); app.filter("reverse", function myfunction() { return function (input) { var result = ""; input = input || ""; for (var i = 0; i < input.length; i++) { result = input[i]+result; } return result; }; }); </script> </head> <body ng-app="MyApp"> <div> <input type="text" name="name" ng-model="text" placeholder="Enter text" /> <p>Input: {{text}}</p> <p>Filter Input :{{ text | reverse }}</p> </div> </body> </html>
Summary:
In this example we learnt to create the custom filter depending on our own requirement in angularJs.