0

I have the following HTML Code. This is a table that fetches a list of items from costList and displays them in different rows. I want the item value to be displayed on the row click. How do I implement it in Angular. Thank You in advance.

    <table>
        <tr ng-click = "displayItem()" ng-repeat = "item in costList">
            <td>{{item}}</td>
        </tr>
    </table>
1
  • You can pass the item as a parameter in your displayItem() function like this displayItem(item) and use it Commented Jun 16, 2017 at 13:05

3 Answers 3

1
ng-click="displayItem(item)"

or you can store the item in displayItem.

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

<div>{{currentItem}}</div>
Sign up to request clarification or add additional context in comments.

1 Comment

that was Easy ! Thanks Man
0

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

<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

Comments

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

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.