简体   繁体   中英

AngularJS ng-click work

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM