0
<li ng-repeat="item in data" ng-click="myFunc('{{ item.name }}')">

I can't seem to get ng-click to pass the varible value of item.name. It actually sends:

{{ item.name }}

An example in Plunker: http://plnkr.co/edit/dq5KA3?p=preview

In the console it looks ok, but doesn't actually work:

enter image description here

3 Answers 3

1

ng-click is actually an expression, so you should be able to set it as ng-click='myFunc(item.name)'. This will pass the actual value of item.name rather than trying to pass the string value of the raw text as your current implementation is doing.

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

Comments

1

Use:

<li ng-repeat="item in data" ng-click="myFunc(item.name)">{{item.name}}
</li>

Because item is an object.


Explanation about the results in the console, in your scenario:

Always: {{item.name}} It will print the value, this is why you see in the console:

<li ng-repeat="item in data" ng-click="myFunc('Apple')" class="ng-binding ng-scope">Apple
</li>

Because you have in your page:

 <li ng-repeat="item in data" ng-click="myFunc('{{ item.name }}')">{{item.name}}
 </li>

Comments

0

ng-click is actually an angular directive not an expression, you need to give brackets when you are passing value to the expression but you do not need to use brackets when you pass values to directive.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.