Is it possible to extend existing \"standard\" filters (date
, number
, lowercase
etc)?
In my case I need to parse date from YYYYMMDDhhm
I prefer to implement the decorator pattern, which is very easy in AngularJS.
If we take @pkozlowski.opensource example, we can change it to something like:
myApp.config(['$provide', function($provide) {
$provide.decorator('dateFilter', ['$delegate', function($delegate) {
var srcFilter = $delegate;
var extendsFilter = function() {
var res = srcFilter.apply(this, arguments);
return arguments[2] ? res + arguments[2] : res;
}
return extendsFilter;
}])
}])
And then in your views, you can use both.. the standard output and the extended behavior.
with the same filter
Standard output : {{ now | date:'yyyyMMddhhmmss' }}
External behavior : {{ now | date:'yyyyMMddhhmmss': ' My suffix' }}
Here is a working fiddle illustrating both techniques: http://jsfiddle.net/ar8m/9dg0hLho/