4

Is there a way to use filter inside a ng-if statement ?

for example:

   <div ng-if="someVarString == ('someValue' | translate )">
        <span>Hello</span>
    </div>

Note: the translate filter returns a string

I know how to do it inside the controller, but I would like to use on the HTML

1
  • 2
    What happens when you try it? The answer should be "Yes" Commented Jul 16, 2015 at 15:09

1 Answer 1

5

Yes that works. Here's a plunkr: http://plnkr.co/edit/vpCzutMnEFlTWC9gceU3?p=preview

angular.module('plunker').filter('two', function() {
  return function (input) { return 2; }
});

Equivalent of your code:

<div ng-if="2 == ('foobar' | two )">
  <span>Hello</span>
</div>

So your problem must be elsewhere.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.