In previous post, we have seen about angularJS inbuilt filter. In this post, we are going to how to create your own filters.
AngularJS tutorial:
Filters are used to format data in desired way.
For creating a filter , you need to attach it with the module.
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 !!!
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