Table of Contents
AngularJS tutorial:
For creating a filter , you need to attach it with the module.
1 2 3 4 5 6 7 8 9 10 |
angular.module('myApp') .filter('customFilter', function () { return function (input) { if (input) { return input; } }; }); |
Example:
Copy below text , open notepad , paste it and save it as angularJSCustomFilterExample.html and open it in the browser.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Angular js</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script> <script> var app = angular.module('myApp', []); app.controller('java2blogContoller', function($scope) { $scope.java2blogMsg = "Hello_from_Java2blog"; }).filter('java2blogFilter',function(){ return function( str ) { return str.toUpperCase().replace(/_/g,' '); } }); </script> </head> <body> <div ng-app="myApp" ng-controller="java2blogContoller"> </br> {{java2blogMsg|java2blogFilter}} !!! </div> </body> </html> |
1 2 3 |
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