0

My application depends on two filter applications like

 var app = angular.module('MyApp',['Filter1','Filter2']);

where both the applications have filters with same name like

 var filterapp1 = angular.module('Filter1',[]);
 filterapp1.filter('replace',function(){return function(input){ 
             return input + " from Filter1 app";
 }});

 var filterapp2 = angular.module('Filter2',[]);
 filterapp2.filter('replace',function(){return function(input){ 
             return input + " from Filter2 app";
 }});

Now in my application if i want to refer the filter from the filterapplication1, How can i can i do?

In my HTML i have something like

 {{'Hello World' | replace }} 

where the output should be "Hello World from Filter1 app" but i am getting "Hello World from Filter2 app". How to override the filters? Or do filters override by order they are injected? How to overcome this?

1

1 Answer 1

3

In Angular "last one wins". So if you want to use both filters, you should name them differently. For example, filter('module1.replace',....)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank valentyn. But how it is possible with big application with multiple modules.
In my practice we started naming keeping in mind that AngularJS has 'last wins' principle, so we just named everything inside module prefixing module name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.