我试图使用http://keith-wood.name/realPerson.html jQuery插件创建一个验证码指令。在指令中将jquery生成的隐藏字段绑定到angularjs模型
我是相对较新的angularjs,似乎无法找到一种方法来做到这一点。基本上我想要一个验证码来验证一个人正在注册他们的帐户。调用element.realperson()将生成一个隐藏的输入字段,其中有一些散列值,我需要将它与在服务器端输入的输入进行比较。所以如果我把这个非常基本的和不完整的指令称为它,它会将newUser.captchaInput模型绑定到输入表单,但是我不能为我的生活弄清楚如何获取隐藏的字段值$(' #captcha_hash')。val()并以某种方式将它包含在表单数据中。理想的情况是newUser.captchaHash。
angular.module('vah').directive("captcha", ->
restrict: "A"
require: '?ngModel'
link: (scope, element, attrs, ngModel) ->
return if !ngModel
optionsObj = {
length: 5
}
element.realperson(optionsObj)
# need to bind $('#captcha_hash').val() to a newUser.captchaHash model, or
add the model to that generated input field.
)
<input captcha id="defaultReal" ng-model="newUser.captchaInput">
我确信有一个简单的解决方案,并希望有任何帮助。
意外downvote,对不起! – 2013-07-05 11:18:57
没关系@MichaelRobinson。您可以通过再次单击箭头来撤消它:) – 2013-08-20 23:50:05
投票被锁定,除非答案被编辑(感谢提示,尽管:P) – 2013-08-21 01:57:37