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...

Naigel
  • 9,086
  • 16
  • 65
  • 106
  • No need for interpolation on directives. – Shikloshi Sep 28 '15 at 15:55
  • is 1 a variable you set in your controller? – code Sep 28 '15 at 15:56
  • 1
    possible duplicate of [Difference between double and single curly brace in angular JS?](http://stackoverflow.com/questions/17878560/difference-between-double-and-single-curly-brace-in-angular-js) – azium Sep 28 '15 at 15:57

1 Answers1

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

Community
  • 1
  • 1
Felipe Skinner
  • 16,246
  • 2
  • 25
  • 30