Angular JS,给ng-repeat添加过滤条件
Angular JS, add filter condition to ng-repeat
我有这个:
<td ng-repeat="link in fund.pdfLinks track by $index" class="fundLitCmpnt-linkWrap"><a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}"><i class="sprite pdfIcon"></i></a></td>
我想向 ng-repeat 添加一个过滤器,所以如果 link.url
是一个特定的字符串 (/myfolder/mypage.aspx)。我不想显示那个锚标记。
我试过这个:
<td ng-repeat="link in fund.pdfLinks track by $index | filter:link.url'!=/myfolder/mypage.aspx'}" class="fundLitCmpnt-linkWrap"><a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}"><i class="sprite pdfIcon"></i></a></td>
如何将 link.url
与特定字符串进行比较?请帮忙
尝试使用 ng-hide。
如果 link url 计算字符串
,它将隐藏当前元素
<td ng-repeat="link in fund.pdfLinks track by $index"
ng-hide="link.url=='/myfolder/mypage.aspx'"
class="fundLitCmpnt-linkWrap">
<a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}">
<i class="sprite pdfIcon"></i>
</a>
</td>
如果你也想隐藏里面的元素,你可以单独使用 ng-hide 或者可以使用 span/div like
<td ng-repeat="link in fund.pdfLinks track by $index"
class="fundLitCmpnt-linkWrap">
<div ng-hide="link.url=='/myfolder/mypage.aspx'">
<a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}">
<i class="sprite pdfIcon"></i>
</a>
</div>
</td>
在你的情况下,更好的方法是使用 ng-hide 或 ng-if,但你也可以通过过滤器来实现它
angular.module('YourModule').filter('customFl',function(url){
return url !='your_url'
})
<td ng-repeat="link in fund.pdfLinks track by $index | customFl' " class="fundLitCmpnt-linkWrap"><a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}"><i class="sprite pdfIcon"></i></a></td>
帮助愉快!
我有这个:
<td ng-repeat="link in fund.pdfLinks track by $index" class="fundLitCmpnt-linkWrap"><a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}"><i class="sprite pdfIcon"></i></a></td>
我想向 ng-repeat 添加一个过滤器,所以如果 link.url
是一个特定的字符串 (/myfolder/mypage.aspx)。我不想显示那个锚标记。
我试过这个:
<td ng-repeat="link in fund.pdfLinks track by $index | filter:link.url'!=/myfolder/mypage.aspx'}" class="fundLitCmpnt-linkWrap"><a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}"><i class="sprite pdfIcon"></i></a></td>
如何将 link.url
与特定字符串进行比较?请帮忙
尝试使用 ng-hide。
如果 link url 计算字符串
,它将隐藏当前元素<td ng-repeat="link in fund.pdfLinks track by $index"
ng-hide="link.url=='/myfolder/mypage.aspx'"
class="fundLitCmpnt-linkWrap">
<a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}">
<i class="sprite pdfIcon"></i>
</a>
</td>
如果你也想隐藏里面的元素,你可以单独使用 ng-hide 或者可以使用 span/div like
<td ng-repeat="link in fund.pdfLinks track by $index"
class="fundLitCmpnt-linkWrap">
<div ng-hide="link.url=='/myfolder/mypage.aspx'">
<a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}">
<i class="sprite pdfIcon"></i>
</a>
</div>
</td>
在你的情况下,更好的方法是使用 ng-hide 或 ng-if,但你也可以通过过滤器来实现它
angular.module('YourModule').filter('customFl',function(url){
return url !='your_url'
})
<td ng-repeat="link in fund.pdfLinks track by $index | customFl' " class="fundLitCmpnt-linkWrap"><a class="fundLitCmpnt-link" target="_blank" href="{{link.url}}"><i class="sprite pdfIcon"></i></a></td>
帮助愉快!