Creating a custom filter in angularjs
Today we will create a custom filter in angularjs.
We need to invoke "filter" function on the module to create a custom filter. Filter function takes two arguments first being the name of the filter and the second one is a function.
So as shown above I have created a filter which returns a formatted output prefixing Indian Rupee symbol.
Now to consume it I need to write something like this in index.html file.
That simple it is to create a custom directive.
You can find the working demo here
We need to invoke "filter" function on the module to create a custom filter. Filter function takes two arguments first being the name of the filter and the second one is a function.
var app=angular.module('app',[]);app.filter('inr',function(){
return function(input){
return '\u20B9'+ ' '+input;
}
});
So as shown above I have created a filter which returns a formatted output prefixing Indian Rupee symbol.
Now to consume it I need to write something like this in index.html file.
{{500|inr}}
That simple it is to create a custom directive.
You can find the working demo here
Comments
Post a Comment