Chris Paterson
Chris Paterson

Reputation: 1149

How can I bind a parameter inside of ng-click?

The best way to explain what I'm trying to do is to just show you an example. Here is the code I have:

<div ng-click="doSomething('path/to/script/with/{{parameter}}')">Click Here</div>
<div>Parameter is {{parameter}}</div> // I can see parameter here

The problem is that {{parameter}} is not binding to the ng-click. I can manually enter the parameter (e.g., '12') and the ng-click works fine, but I don't want to set it manually.

I have tried the following, but none of them work:

<div ng-click="doSomething('path/to/script/with/parameter')">Click Here</div>
<div ng-click="doSomething('path/to/script/with/'parameter)">Click Here</div>

Any ideas?

Upvotes: 1

Views: 179

Answers (1)

Matsemann
Matsemann

Reputation: 21854

try

<div ng-click="doSomething('path/to/script/with/' + {{parameter}})">Click Here</div>

or

<div ng-click="doSomething('path/to/script/with/' + parameter)">Click Here</div>

or just read them from scope in your function.

Upvotes: 1

Related Questions