0

我想實現一個簡單的ng-click,當用戶在第一個實例中點擊一個鏈接時顯示一些東西,在第二個實例中,現在顯示的是同樣的東西隱。AngularJS - ngclick上2次點擊不起作用

這裏是我的html:

<table> 
<tbody ng-repeat-start="history in HistoryByCategory.HistoryByCategory[key]"> 
    <tr> 
     <th>{{ history.CompanyName}}</th> 
     <td ng-repeat="storyone in history.Histories.slice(1, 12)"> 
       {{ storyone.value }} 
     </td> 

    </tr> 
</tbody> 
<tbody ng-repeat-end> 
    <tr> 
     <th ng-model="collapsed" ng-click="collapsed=!collapsed"><a>13 - 24 months</a> 

      <!-- <div ng-show="collapsed"> 
      When placed ng-show in here, shows/hides fine. 
      </div> --> 

     </th> 

     <td ng-repeat="historyone in history.Histories.slice(12, 24)" ng-show="collapsed"> 
      {{ historyone.value }} 
     </td>        
    </tr> 
</tbody> 
</table> 

從上面的,當用戶點擊:

<th ng-model="collapsed" ng-click="collapsed=!collapsed"><a>13 - 24 months</a></th> 

應顯示/隱藏以下內容:

<td ng-repeat="historyone in history.Histories.slice(12, 24)" ng-show="collapsed"> 
      {{ historyone.value }} 
     </td> 

然而,這不工作。

但是,如果我把:

<div ng-show="collapsed"> 
      When placed ng-show in here, shows/hides fine. 
      </div> 

裏面我tr,這DIV顯示和隱藏。

+0

請做一個工作小提琴或plunker,它會花一些時間來回答它與工作代碼 – maurycy

+1

@maurycy:你是多麼善良和善良:) @ OamPsy:似乎對我工作很好:http:// jsfiddle.net/ExpertSystem/Ukt9C/ – gkalpak

+0

@ExpertSystem - 謝謝,我注意到你的例子你沒有ng-modal的標籤。我從我的應用程序中拿出了這個,然後我工作了,不知道爲什麼這會影響它。我如何接受你的評論作爲答案? –

回答

0

您可以使用指令使用jQuery的幫助:效果slideToggle

.directive('showhide', function () { 
    return { 
     showhide: "=", 
     link: function(scope, elem, attrs) { 
      var link = $('th'); 
      link.click(function() { 
       $('td').slideToggle('slow'); 
      });  
     } 
    }; 
    }) 

或 「範圍」 變量( 「秀」 爲例)存儲可見性:

<th ng-click="show=!show"><a>13 - 24 months</a></th> 

<div ng-if="show"> 
    <td ng-repeat="historyone in history.Histories.slice(12, 24)"> {{ historyone.value }} </td> 
<div>