2017-06-20 56 views
0

首先讓我請接受angular和html不是我的交易。ng中的div與ng - 如果沒有篩選結果

以下是我的方案

<tbody ng-repeat="item in items.ItemList"> 
    <div ng-if="item.variableName == false"> 
     <tr> 
     <tr/> 
     <tr ng-show="isPermitted" ng-animate="isPermitted"> 
     <tr/> 
    </div> 
</tbody> 

我試圖控制我wan't與ng-if的DIV中顯示的錶行,它不工作。通過移動ng-iftbody將過濾行很好,但不在div級別。 不幸的是,我不能移動ng,因爲我必須處理if條件的else部分,並且在那種情況下,中繼器的每個項目中都有一個數組,它應該分別渲染行。 以下是我想要有的輸出ng-if條件適當工作。

P.S.我不是特定於此處的<div>標籤。我打開可以用任何其他標籤替換div,只要它可以得到我想要的結果。 這裏有人可能會說爲什麼不是ng-if<tr>級別?我正在使用ng-showng-animate,所以具有ng-if的行在Doom對象中更改其作用域並將鼠標懸停在功能上停止工作。

<tbody ng-repeat="item in items.ItemList"> 
    <div ng-if="item.variableName == false"> 
     <tr> 
     <tr/> 
     <tr ng-show="isPermitted" ng-animate="isPermitted"> 
     <tr/> 
    </div> 
    <div ng-if="item.variableName == true"> 
     <tr> 
     <tr/> 
     <trng-show="isPermitted" ng-animate="isPermitted"> 
     <tr/> 
    </div> 
</tbody> 
+0

這種方法 爲例看是錯誤的。 div無效tbody的孩子。 – Ved

+0

比我可以使用的還要多。任何選擇?也嘗試跨度。不知道即使這是有效的。 –

+1

使用標記,還使用ng-if =「item.variableName」和ng-if =「!item.variableName」。 –

回答

0

部門不會幫助你在這裏,因爲它根據HTML藐視tbody規則。這樣

使用NG-容器,相反,它是沒有意義的HTML,所以它不會藐視規則,你會得到你的病情,你的情況符合

<tbody ng-repeat="item in items.ItemList"> 
    <ng-container ng-if="item.variableName == false"> 
     <tr> 
     <tr/> 
     <tr ng-show="isPermitted" ng-animate="isPermitted"> 
     <tr/> 
    </ng-container> 
    <ng-container ng-if="item.variableName == true"> 
     <tr> 
     <tr/> 
     <trng-show="isPermitted" ng-animate="isPermitted"> 
     <tr/> 
    </ng-container> 
</tbody> 

您也可以使用NG-交換機而不是NG,如果這樣

<tbody ng-repeat="item in items.ItemList" ng-switch="item.variableName"> 
     <ng-container ng-switch-when="false"> 
      <tr> 
      <tr/> 
      <tr ng-show="isPermitted" ng-animate="isPermitted"> 
      <tr/> 
     </ng-container> 
     <ng-container ng-switch-when == "true"> 
      <tr> 
      <tr/> 
      <trng-show="isPermitted" ng-animate="isPermitted"> 
      <tr/> 
     </ng-container> 
    </tbody> 
+0

不幸的是,在ng-container中它仍然顯示值爲true和false的所有行 –

+0

以下是我試過你的方法的小提琴鏈接,它不起作用。你能告訴那裏有什麼問題嗎? http://jsfiddle.net/ADukg/11999/ –

1

我用這個和它的工作。在jsfilddle

http://jsfiddle.net/ADukg/12003/

<tbody ng-repeat="item in items.ItemList" ng-show="item.variableName"> 
      <tr>{{item | json}}</tr> 

    </tbody> 
+0

我知道它在tbody級別運行良好,並且已經在我的問題中解釋了爲什麼我不使用這種方法。 –

+0

Vous pouvez utiliser une nouvelle tableàl'intérieurde votre Tbody pour votre condition si vous le souhaitez。或嘗試使用和ng-include。 – nevradub