我可以在 ngIf 语句中使用过滤器吗

Can I use filters inside ngIf statement

有没有办法在 ng-if 语句中使用过滤器?

例如:

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

注意:翻译过滤器returns一个字符串

我知道如何在控制器中使用,但我想在 HTML

上使用

是的,行得通。这是一个 plunkr:http://plnkr.co/edit/vpCzutMnEFlTWC9gceU3?p=preview

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

等同于您的代码:

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

所以你的问题一定出在其他地方。