简体   繁体   English

在JavaScript函数中使用AngularJS值

[英]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. 我有一个函数,该函数使用Jcrop API调用一些代码,该代码需要一些值来设置纵横比。 However, I need those values to come from a data connection for which I'm using Angular. 但是,我需要这些值来自我使用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). 然后valueToSet实际上会求值,但是我不能这样称呼它,因为在任何控制器中都没有定义setAspectRatio() (这是我页面上的脚本)。 This is mainly because it uses Jcrop and I didn't want to mix Jcrop with my Angular controller. 这主要是因为它使用Jcrop,并且我不想将Jcrop与我的Angular控制器混合使用。

How can I accomplish what I'm trying to do here? 我该如何完成在这里要做的事情?

You don't need the {{}} around the variable name. 您不需要在变量名周围使用{{}}。 ng-click=setAspectRatio(valueToSet) should work. ng-click = setAspectRatio(valueToSet)应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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