0

I have two filter which need to applied on the content of controller. First filter will be lowercase and other one is custom filter.

I tried to use it like follows:

$filter('lowercase','cardShortNameRegex')(currentProductObject.shortName);

Only lowercase filter get applied not the other one.

if some one have any solution or suggestion please help.

1 Answer 1

1

Just call it one after another.

var lowerCasedName = $filter('lowercase')(currentProductObject.shortName);
var result = $filter('cardShortNameRegex')(lowerCasedName);

You can also define your own function something like this:

var result = multipleFilters('lowercase', 'cardShortNameRegex')(currentProductObject.shortName);

function multipleFilters() {
  var filters = arguments;
  return function (input) {
    angular.forEach(filters, function (filterName) {
      input = $filter(filterName)(input);
    });
    return input;
  }
}

which accepts multiple filter names and applies them.

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

2 Comments

Is there any other way available? If there is any single line solution for it that will be good because I have to do it many places for different conditions.
@Toretto I updated my answer with another possible solution

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.