1

I'm trying to show some details about a list of procedures using an AngularJS function. Every procedure is identified by a unique ID so I use it as a parameter in the function.

If I use this line of code it works

<a ng-click="showDetails(1)">Show Details</a>

While using this one it doesn't work

<a ng-click="showDetails({{1}})">Show Details</a>

Shouldn't everything inside double braces be solved?


EDIT: seems obvious but, given the comments, it isn't...

This is an example to understand why argument isn't fine this way, in my production version I need to perform much advanced calculations that writing 1...

3
  • No need for interpolation on directives. Commented Sep 28, 2015 at 15:55
  • is 1 a variable you set in your controller? Commented Sep 28, 2015 at 15:56
  • 1
    possible duplicate of Difference between double and single curly brace in angular JS? Commented Sep 28, 2015 at 15:57

1 Answer 1

1

When you're calling a directive, such as ng-click, you are already evaluating any JS you throw inside it because they accept an expression.

So, if you try calling ng-click="showDetails({{1}})" it's the same as calling a function with a JS object {} wrapping another object {1}. Where 1 is just an usual string/number

You could take a further read into this one: Difference between double and single curly brace in angular JS?

[EDIT] I guess this link could help you even more than the previous one: How to get evaluated attributes inside a custom directive

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

1 Comment

you're welcome! i´ve edited the answer to add another link that seems to fit your question better

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.