可能会遗漏一些简单的语法,但我似乎无法使用相同的过滤器来工作:
我能做到
filter: {property:{text:'yes'}}
,
但不是
filter: {property:{text:'!yes'}}
,
适用于非嵌套对象。
HTML:
<ul>
<li ng-repeat="attr in attributes | filter: {property:{text:'!yes'}}">
{{attr.property.text}}
</li>
</ul>
JS:
$scope.attributes = [
{property: { text:'yes' }},
{property: { text:'no' }},
];
Plunkr链接:
答案 0 :(得分:6)
您可以使用ng-if
获得与此类似的效果:
<ul>
<li ng-repeat="attr in attributes" ng-if="attr.property.text !== 'yes'">
{{attr.property.text}}
</li>
</ul>
或者,您可以编写包含逻辑的自定义过滤器或以某种方式展平原始结构。我不认为嵌套结构中支持!
。
答案 1 :(得分:4)
您可以使用
filter: !{property:{text:'yes'}}
这在您无法使用ng-if
之类
<select ng-options="element in elementList | filter: !{property: {text:'yes'} }" />
(我知道你可以在选项中使用ng-repeat
,但你明白我的意思......)