2016-04-06 33 views
1

我有一個表與ng-repeat <tr>在與最後td我有編輯/刪除鏈接,我只希望他們顯示,如果用戶懸停在<tr>顯示編輯/刪除鏈接時懸停在數據列上

<tr ng-repeat="form in allData | filter:search | orderBy: orderByValue : orderIn" ng-click="set_index($index)"> 
      <td><a ng-href={{form.link}}>{{form.ar_ref}}</a></td> 
      <td>{{form.title}}</td> 
      <td>{{form.category}} 
      <span ng-class="{'show_edit_link', $index==selected_index}"> 
       <button ng-click="showUpdate()">Update</button> 
       <button ng-click="showDelete()">Delete</button> 
      </span> 
      </td> 
     </tr> 

我的JS控制器:

pp.controller('formsListCtrl', ['$scope', '$http', function($scope, $http){ 

    $http.get('/php_user/formJSON.php').success(function(response){ 
    $scope.allData=response; 

    //Show hover edit links 
    $scope.selected_index = 0; 
    $scope.set_index = function(i){ //i is the $index that we will pass in when hover in the forms_admin.php 
     $scope.selected_index = i; 
    } 

CSS:

.edit_link_show{ 
    display: inline; 
} 
.edit_link{ 
    display: none; 
} 
+1

這有什麼錯絡CSS? http://codepen.io/anon/pen/ONzVLL –

+0

oOo〜好,聰明。 –

回答

1

療法e是ng控制器中的語法錯誤。它應該是類名後表達的:,你也想爲不SELECTED_INDEX等於$指數另一納克級的說法:

<tr ng-repeat="form in allData | filter:search | orderBy: orderByValue : orderIn" ng-click="set_index($index)"> 
      <td><a ng-href={{form.link}}>{{form.ar_ref}}</a></td> 
      <td>{{form.title}}</td> 
      <td>{{form.category}} 
      <span ng-class="{'show_edit_link': $index==selected_index, 'edit_link': $index!=selected_index}"> 
       <button ng-click="showUpdate()">Update</button> 
       <button ng-click="showDelete()">Delete</button> 
      </span> 
      </td> 
     </tr> 
+0

好的調用,這個語法的一個很好的提示是,ng-class等於一個對象,應該像其他對象一樣遵循與key:value對相同的結構。 –