2016-04-06 28 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对相同的结构。 –