Javascript 在angularJS中集成验证码的最佳方法

Javascript 在angularJS中集成验证码的最佳方法,javascript,angularjs,forms,angularjs-directive,captcha,Javascript,Angularjs,Forms,Angularjs Directive,Captcha,我对angularJS比较陌生,我想知道以下问题的最干净的解决方案是什么。 假设我有一个如下的表格 <form name="contactform"> <select id="salutation" name="salutation" required="true" ng-model="contactRequest.salutation"><option value="Herr" selected="">Herr</option><op

我对angularJS比较陌生,我想知道以下问题的最干净的解决方案是什么。 假设我有一个如下的表格

<form name="contactform">
   <select id="salutation" name="salutation" required="true" ng-model="contactRequest.salutation"><option value="Herr" selected="">Herr</option><option value="Frau">Frau</option></select>

   <img width="255" height="70" alt="" src="/website/var/tmp/aed4d639a26c4614cdac2a967381c61c.png" name="captcha[img]"> 

   <captcha-reloader reload-url="/refresh-captcha" img-tag-name="captcha[img]" hidden-field-name="captcha[id]"></captcha-reloader>

   <input type="text" name="captcha[input]" required="true" ng-model="contactRequest.captcha.input">                

   <input type="text" style="display: none;" ng-model="contactRequest.captcha.id" value="aed4d639a26c4614cdac2a967381c61c" name="captcha[id]">   
...
此外,我必须初始化select box和captcha的值,否则它们不会被发送(因为它们没有被触动)。有没有办法避免这种情况


PS:我找到了reCAPTCHA指令,但由于样式限制,reCAPTCHA没有选项。

非常简单,请按照以下步骤操作

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer></script>

<script>
    var onloadCallback = function() {
        widgetId1 = grecaptcha.render('example1', {
            'sitekey' : 'Site-Key-',
            'theme' : 'light'
        });
    };
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer>
    myApp.controller('KontaktCtrl', function ($scope, $location, CustomerDataService, CaptchaService) {
    $scope.contactRequest = {
        salutation: 'Herr',
        captcha: {
            id: initialCaptchaId
        }
    };
    $scope.errors = {};

    $scope.submitAction = function () {
        CustomerDataService.sendRequest($scope.contactRequest).then(function (res) {
            var data = res.data;
            if (res.data.data !== null) { //errors in form. Display them
                //error handling
                $scope.reloadCaptcha();
            } else {
                goToHomeView();
            }
        }, function (error) {
            console.log('An error occurred while updating!', error);
        });
    };


    var goToHomeView = function () {
        $location.path('/');
    };
});
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer></script>

<script>
    var onloadCallback = function() {
        widgetId1 = grecaptcha.render('example1', {
            'sitekey' : 'Site-Key-',
            'theme' : 'light'
        });
    };
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer>
<div id="example1"></div> 
<p style="color:red;">{{ captcha_status }}</p>
if(grecaptcha.getResponse(widgetId1)==''){
    $scope.captcha_status='Please verify captha.';
    return;
}