0

I want to send an AngularJS variable to a function in my controller. Here's a sample snippet of my code:

<ul>
    <li ng-repeat="score in scores | filter:search | orderBy : 'first'">
        <span class='popup' ng-click='popup("/scores/create/{{ score.user_id }}")'>Add Score</span>
    </li>
</ul>

When I inspect the ng-click attribute in my browser, I see the processed variable I need: "/scores/create/60".

But when I click on the element and the function is fired, it returns the preprocessed AngularJS code: "/scores/create/{{ score.user_id }}", thus breaking my function. Is there a way around this?

1
  • You just can send ng-click='popup("/scores/create/" + score.user_id) (without double brackets) Commented Aug 4, 2014 at 21:49

1 Answer 1

1

You are already "in" angular, so you don't need to use {{}}, you just have to get out of the string you are passing in:

 ng-click='popup("/scores/create/" + score.user_id)'
Sign up to request clarification or add additional context in comments.

1 Comment

Could have sworn I tried that already! Embarrassing when it's so simple. Thanks!

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.