Can I use filters inside the ngIf operator

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

eg:

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

Note: the translation filter returns a string

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

+4
source share
1 answer

Yes it works. Here plunkr: http://plnkr.co/edit/vpCzutMnEFlTWC9gceU3?p=preview

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

Equivalent to your code:

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

So your problem should be elsewhere.

+5
source

Source: https://habr.com/ru/post/1598246/


All Articles