[英]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或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>
快樂的幫助!
嘗試使用ng-hide。
如果鏈接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
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.