2015-03-08 57 views
-1

我有這樣的:角JS,添加篩選條件NG-重複

<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-重複,所以如果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與特定的字符串?請幫忙。

回答

1

嘗試用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隱藏或可以使用跨度/每格狀

<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> 
+0

這是工作,但它隱藏了整個TD元素,這是搞亂我的表格佈局....我只是想隱藏所有在td裏面? – Phani 2015-03-08 19:53:00

+0

@Phani檢查更新的答案 – 2015-03-08 19:55:15

+0

@ A.B that worked ....謝謝! – Phani 2015-03-12 18:44:48

2

在你的情況最好的方法是使用NG隱藏或NG-IF,但你也可以通過過濾器acheive它

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> 

快樂幫助!