AngularJS custom filter example

Filters are used to format data in desired way.
For creating a filter , you need to attach it with the module.

angular.module('myApp')
  .filter('customFilter', function () {
    return function (input) {
      if (input) {
        return input;
      }
    };
  });

Lets take example where we will convert string to upper case and replace “_” by space(” “).

Example:

Copy below text , open notepad , paste it and save it as angularJSCustomFilterExample.html and open it in the browser.

  
  
  
  
Angular js  
  
 
  
  
{{java2blogMsg|java2blogFilter}} !!!

Output:

HELLO FROM JAVA2BLOG !!!

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Comments

  1. Very nice post… Thanks..

    can you please tell me more about ——-> replace(/_/g,' ');
    and whats g in it. or can refer some links to know about it.

    thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.