Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a code that looks something like this:

<tr ng-repeat="obj in objs">
  <td onClick = "someFunction({{obj.val1}})">{{obj.val2}}</td>
  <td>{{obj.val3}}</td>
</tr>

The colums properly show val2 and val3, but the onclick method I'm trying to define doesn't work as the code doesn't translate from {{obj.val1}} into the proper value, it stays as is.

How do I properly send {{obj.val1}} onto the onClick event? Can this be done?

share|improve this question
1  
try ng-click="someFunction(obj.val1)" – Balaji M 1 hour ago
up vote 1 down vote accepted

Use ng-click instead of onClick and assign the someFunction() function to angular $scope

share|improve this answer
    
While everyone is technically correct, only you mentioned that I had to also put the function inside $scope to be able to use it with ng-click, so I'm choosing your answer – Artemio Ramirez 56 mins ago
    
Good luck with your project! – Karlen 54 mins ago

Yes it can be done.Using ng-click

    <tr ng-repeat="obj in objs">
    <td ng-click = "someFunction(obj.val1)">{{obj.val2}}</td>
    <td>{{obj.val3}}</td>
    </tr>

You don't need to bind the values using {{}}, you can simply put them as function parameters.

share|improve this answer

In angular they already have directive called ng-click The ngClick directive allows you to specify custom behavior when an element is clicked. which used for click event. And You don't need to bind the parameter {{}}

then your code come like

<tr ng-repeat="obj in objs">
  <td ng-click = "someFunction(obj.val1)">{{obj.val2}}</td>
  <td>{{obj.val3}}</td>
</tr>
share|improve this answer

Do this :

<td onClick = "someFunction(obj.val1)">{{obj.val2}}</td>
share|improve this answer
    
I had already tried this, and it doesn't work – Artemio Ramirez 56 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.