Calling Angular.js filter with multiple arguements
It is easy to call a filter like date which has only one arguement. In the case of more than one arguement how would you do that?. You have to call filters with parameters from both templates and java script code. The syntax for calling filters in templates is given below. You can add colons to seperate filter arguements.
{{ yourExpression | yourFilter: arg1:arg2:... }}
In JavaScript you can call filters as given below.
$filter('yourFilter')(yourExpression, arg1, arg2, ...)
An example is given below:
myApp.filter("regexReplace",function() { // register new filter
return function(input, searchRegex, replaceRegex) { // filter arguments
return input.replace(RegExp(searchRegex), replaceRegex); // implementation
};
});
Adding filter in the template to censor out all numbers.
<p>{{ myText | regexReplace: '[0-9]':'X' }}</p>
Comments
0 comments
Please Sign in or Create an account to Post Comments