简体   繁体   English

获取表中单击的行-AngularJS

[英]Get row clicked in a table - AngularJS

I have the following HTML Code. 我有以下HTML代码。 This is a table that fetches a list of items from costList and displays them in different rows. 这是一个表,用于从costList中获取项目列表,并将其显示在不同的行中。 I want the item value to be displayed on the row click. 我希望在单击行时显示项目值。 How do I implement it in Angular. 如何在Angular中实现它。 Thank You in advance. 先感谢您。

    <table>
        <tr ng-click = "displayItem()" ng-repeat = "item in costList">
            <td>{{item}}</td>
        </tr>
    </table>
ng-click="displayItem(item)"

or you can store the item in displayItem. 或者您可以将项目存储在displayItem中。

$scope.displayItem = function (item) { $scope.currentItem = item; }

<div>{{currentItem}}</div>

It depends on what you mean by "I want the item value to be displayed on the row click". 这取决于您的意思是“我希望在单击行时显示项目值”。 If you just want it to appear when the row is clicked, try this: 如果只希望在单击行时显示它,请尝试以下操作:

HTML 的HTML

<table>
  <tr  ng-repeat = "item in costList">
    <td ng-click="display = !display">
      <span ng-show="display">{{item}}</span>
    </td>
  </tr>
</table>

Plunkr: https://plnkr.co/edit/BSjv4Bv7Ouf4Y49cAtgx?p=preview Plunkr: https ://plnkr.co/edit/BSjv4Bv7Ouf4Y49cAtgx ? p = preview

 <table>
        <tr ng-click = "selectedItem = item" ng-repeat = "item in costList">
            <td>{{selectedItem}}</td>
        </tr>
    </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM