Google Groups

Re: [AngularJS] Is it possible to extend or override existing filters?


Witold Szczerba Sep 2, 2012 3:57 PM
Posted in group: AngularJS
Hi,
I am not sure if it is possible to override filters - check it out.
However, I would suggest not doing so - even if that is allowed.
Predefined filters are the public API of AngularJS. What if some parts
of AngularJS use some of them internally or one day you install some
add-on which depends on that filter?

By the way: there is no need to inject $filter, you can specify which
exactly filters you want on injection point, so you are more specific
about real dependencies:
myApp.filter('myDate', function(dateFilter){
    return function(date){
     return 'prefix ' + dateFilter(date, 'yyyyMMddhhmmss');
    }
});

Regards,
Witold Szczerba

On 2 September 2012 23:16, Konstantin Cherkasoff <k.cher...@gmail.com> wrote:
> Hi Pawel!
>
>
>> Responded on SO:
>>
>> http://stackoverflow.com/questions/12236905/how-to-extend-or-override-existing-filters-in-angularjs/12237229#12237229
>
> myApp.filter('customDate', function($filter){
>     var standardDateFilterFn = $filter('date');
>     return function(dateToFormat){
>      return 'prefix ' + standardDateFilterFn(dateToFormat,
> 'yyyyMMddhhmmss');
>     }
> });
>
> Thank you for this example.
> Actualy in my case it would be better for me to override date filter rather
> than extend.
> Is it possible to define filter like below?
> myApp.filter('date', function($filter){...
>
> --
> Konstantin Cherkasoff
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en.
>
>