0

I have an ng-repeat loop in my html. The variable involved in the looping is displayed in table rows. I need to allow the user to click on the desired value and have a js function receive the value so it can act on it. An earlier version of my code that does not attempt to pass the value, just display it, is here and works as expected; showing the various host values from filteredList with link attributes (underlined, in my case)

<tr data-ng-repeat="update in filteredList">
  <td> <a href="#">{{update.host}}</a> </td>
  <td> {{update.date}} </td>
  <td> {{update.num}} </td>
</tr>

My attempt to pass the value of host that the user clicks on to my function "searcher" is here, but it does not work:

<tr data-ng-repeat="update in filteredList">
  <td> <a href="#" ng-click="searcher({{update.host}})">{{update.host}}</a> </td>
  <td> {{update.date}} </td>
  <td> {{update.num}} </td>
</tr>

When it is encountered, angularjs complains: Error: [$parse.syntax] Syntax Error: Token 'update.host' is unexpected, expecting [:] at column 12 of the expression [searcher({{update.host}});] starting at [update.host}});].

Can someone please advise me of a way acceptable to angularjs to pass the clicked host value to my function?

Thanks very much.

2
  • 1
    ng-click="searcher(update.host)" Commented Nov 21, 2014 at 14:28
  • 2
    You don't need the curly brackets around variables inside the ng-click. Neither in any angular directive parameter for that matter. Commented Nov 21, 2014 at 14:29

3 Answers 3

1

As others have mentioned in the comments, this will work for you:

<a href="#" ng-click="searcher(update.host)">{{update.host}}</a> </td>

Check out the documentation for ng-click, which indicates it accepts an expression (so you don't need the {{binding}} syntax).

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, ofcourse. Thanks to all of you that suggested essentially the same thing. I overlooked the critical piece.
You're welcome, @consultmac. Sometimes all you need is a second set of eyes on a problem.
0

This is the right way to do it

<tr data-ng-repeat="update in filteredList">
  <td> <a href="#" ng-click="searcher(update.host)">{{update.host}}</a> </td>
  <td> {{update.date}} </td>
  <td> {{update.num}} </td>
</tr>

Comments

0

Try:

<td> <a href="#" ng-click="searcher(update.host)">{{update.host}}</a> </td>

As mentioned, you don't need the curly brackets around variables inside the ng-click. Neither in any angular directive parameter for that matter.

Comments

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.