【问题标题】:Showing Edit/Delete links when hover over the data row将鼠标悬停在数据行上时显示编辑/删除链接
【发布时间】:2016-07-27 14:33:32
【问题描述】:

我在<tr> 上有一个带有 ng-repeat 的表格,最后一个 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;
}

【问题讨论】:

标签: css angularjs ng-class


【解决方案1】:

您的 ng-controller 中存在语法错误。对于类名之后的表达式,它应该是 :,并且您还想为 selected_index 设置另一个不等于 $index 的 ng-class 参数:

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

【讨论】:

  • 好的调用,这个语法的一个很好的提醒是 ng-class 等于一个对象,它应该遵循与其他对象一样的 key:value 对的结构。
猜你喜欢
  • 2016-05-25
  • 2017-03-06
  • 1970-01-01
  • 2023-04-04
  • 2013-08-27
  • 1970-01-01
  • 1970-01-01
  • 2014-05-06
  • 2012-06-04
相关资源
最近更新 更多