batman
batman

Reputation: 4918

Pass the value from the iteration to the function parameter

I’m new to angular js and I want to do this. I have code like this:

<tr data-ng-repeat="element in awesomeThings">
    <td ng-click="getServiceDetails()">
        <a href="#">
            {{element}}
        </a>
    </td>
</tr>

In the ng-repeat I want to bind a ng-click for the html dom elements like:

<td ng-click="getServiceDetails()">

The function getServiceDetails() takes one parameter, which is present in the element['id']. How can pass this value to getServiceDetails() function?

Upvotes: 1

Views: 87

Answers (1)

dfsq
dfsq

Reputation: 193291

Pretty straightforward, you are doing this right and pretty typical:

<td ng-click="getServiceDetails(element.id)">

You can of course pass entire object as well:

<td ng-click="getServiceDetails(element)">

or even not pass anything and use this context inside of getServiceDetails function, which would point to current child scope. In this case you simply use this.element.id, etc.

Upvotes: 1

Related Questions