Thursday, 21 April 2016

custom filters in angular:


syntax:
angular.module("module_name").filter('filter_name'), function( dependencie_if_any){

});

Example:
//uppercase is a predefined filter we are passing as a dependency injection, so that we can use it in controller.

angular.module('myApp').filter('capitalize',function(uppercaseFilter){
return function(input,a){
console.log(a);
var result = null;
if(typeof(a) == 'undefined'){

result = uppercaseFilter(input[0])+input.substring(1,input.length);
} else{
result = input.substring(0,a-1) +uppercaseFilter(input[a-1])+input.substring(a,input.length);

}
return result;
}
});


in index.html we can use it as:

{{"saritha chakilala" | capitalize}}
output: Saritha chakilala

[["saritha chakilala" | capitalize : 2]]
sAritha chakilala

No comments:

Post a Comment