一个angular.js过滤器反极性 [英] Reverse polarity of an angular.js filter
问题描述
鉴于如果某些条件得到满足,则返回true过滤器的方法,是有可能援引HTML,例如它的反面使用方法:
Given a filter method that returns true if some condition is met, is it possible to invoke its opposite in HTML, e.g. to use:
"item in items | filter:!AllDay"
而不是
"item in items | filter:AllDay"
?或者你有维护两个单独的过滤方法(一个假,如果为true)?
? Or do you have to maintain two separate filter methods (one for false and one for true)?
推荐答案
正如<一说href=\"http://stackoverflow.com/questions/13278371/angularjs-filter-negated/13450568#13450568\">ENDOH (这太问题在技术上是重复的),你可以通过否定prepending过滤器'!以过滤字符串,像这样的:
As noted by ENDOH (this SO question is technically a duplicate), you can negate a filter by prepending '!' to the filter string, like this:
filter:'!'+myFilter
注意'!被引述。该文档是不会在这个非常清楚,并举例会有帮助。
Note that the '!' is quoted. The documentation is not terribly clear on this, and an example there would be helpful.
这篇关于一个angular.js过滤器反极性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!