muttley91
muttley91

Reputation: 12684

Using AngularJS Values in JavaScript Function

I have a function that calls some code using the Jcrop API that takes in some values to set aspect ratio. However, I need those values to come from a data connection for which I'm using Angular. So I need something like this:

<img src="sample.jpg" onclick="setAspectRatio({{valueToSet}});" />

But I get this error when trying to do it that way. If I do it this way:

<img src="sample.jpg" ng-click="setAspectRatio({{valueToSet}});" />

Then valueToSet actually evaluates, but I can't call it this way as setAspectRatio() isn't defined in any controller (it's a script on my page itself). This is mainly because it uses Jcrop and I didn't want to mix Jcrop with my Angular controller.

How can I accomplish what I'm trying to do here?

Upvotes: 0

Views: 123

Answers (1)

Timothy
Timothy

Reputation: 1160

You don't need the {{}} around the variable name. ng-click=setAspectRatio(valueToSet) should work.

Upvotes: 2

Related Questions