-1

I have the follow code:

 <li class='' ng-click="changeStatus('hello', '{{result.name}}')">

Where 'hello' is my first parameter for changeStatus and I want to pass of binded result.name's value as the second parameter. Does anyone know how to accomplish this?

I tried {{result.name}}, '{{results.name}}' but neither seems to work.

There is probably something simple that am I missing?


I took a look at: Can you pass parameters to an AngularJS controller on creation?

but both the parameters in ng-init were string literals.

1
  • What exactly is result? Can you please clarify? Why couldn't you use something like $scope.result.name in your changeStatus function, like I mentioned in my answer? Commented Sep 24, 2014 at 4:16

3 Answers 3

3

You don't have to pass it. You could just access it in your controller using :

$scope.result.name

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

2 Comments

+1. You are possibly right. however, but I suspect result is not a direct property of $scope because its being used in a <li>. May be its an item in $scope.results
@Mohayemin Had put a question to the OP.
1

If results is an array and you want to pass an individual result to a controller click function you need not decorate it with curly braces. The li will look like this:

<li ng-repeat="result in results" ng-click="changeStatus('hello', result.name)">{{result.name}}</li>

Working Fiddle

Comments

0

Angular treats the content of ng-click as an expression. This means that you write the content as though it is plain javascript (in most cases). For your example, this means leaving out the curly braces (since you are already writing 'javascript').

<li class='' ng-click="changeStatus('hello', result.name)">

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.