0

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?

asked Aug 18, 2014 at 18:34

1 Answer 1

2

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

answered Aug 18, 2014 at 18:37
Sign up to request clarification or add additional context in comments.

4 Comments

OP said that the setAspectRatio function is not on the controller's $scope.
Yeah setAspectRatio has to be defined on the page itself because it uses Jcrop.
Ah, totally missed that. :( have you tried something along the lines of... angular.element(document.querySelector('[ng-controller="controllerNameHere"]')).scope().variableName
Example... something like stackoverflow.com/questions/17960622/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.