Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
    
You just can send ng-click='popup("/scores/create/" + score.user_id) (without double brackets) –  Umidbek Karimov 14 hours ago
    
You're right! Thanks. –  americanknight 14 hours ago

1 Answer 1

up vote 1 down vote accepted

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)'
share|improve this answer
    
Could have sworn I tried that already! Embarrassing when it's so simple. Thanks! –  americanknight 14 hours 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.