2017-11-02 12 views
1

私が直面しています問題は、私はrecaptcha_reponseを印刷する場合、私は出力としてundefinedが表示されます、私はvcRecaptchaService.executeを呼び出した直後に、です。しかし、私がのテスト機能を使って数秒後にrecaptcha_reponseを印刷すると、recaptcha_reponseが表示されます。vcRecaptchaService.execute()の.thenメソッドの使い方私は私のログインフォームにGoogleの目に見えないreCAPTCHAのを追加するための</p> <p>を<a href="https://github.com/VividCortex/angular-recaptcha" rel="nofollow noreferrer">anuglar-recaptcha</a>を使用しています

ここでの問題は、ライブラリ関数vcRecaptchaService.execute()$promiseを返していないことです。その実際に戻るnone

これを約束する方法はありますか?

いただきましISSUE:

// 1. Call this function from html first 
$scope.testRecaptchaExecute = function() { 
    vcRecaptchaService.execute($scope.widgetId); 
    console.log($scope.user.recaptcha_reponse); 
    // undefined :-(
    return(); 
} 

// 2. Call this function from html few seconds after testRecaptchaExecute() is called 

$scope.printRecaptchaReponse = function() { 
    console.log($scope.user.recaptcha_reponse); 
    //JVRk4cZ4J_RluoH2 
} 

私が欲しいもの:のような、このコードの

vcRecaptchaService.execute().then(ret => { //do something here }) 問題がvcRecaptchaService.executeは約束を返さないです 何か。このコードは、

質問のまとめvcRecaptchaService.execute()ため.thenメソッドを使用する方法 に動作しないのだろうか?

+0

'...私はwant' WHAT'でコードをチェック - それは...ああ、 'vcRecaptchaService.execute()'がPromiseを返さないことを除いて... –

+0

あなたはそれを@JaromandaX – Raghu

答えて

1

あなたはrecaptcha

ため、この作業コードを試すことができますJavascriptを

$scope.captcha = { 
    response: null, 
    widgetId: null, 
    modelKey: 'test key', 
    size: 'normal', 
    setResponse: function (response) { 
     $scope.captcha.response = response; 
    }, 
    setWidgetId: function (widgetId) { 
     $scope.captcha.widgetId = widgetId; 
    }, 
    cbExpiration: function() { 
     vcRecaptchaService.reload($scope.captcha.widgetId); 
     $scope.captcha.response = null; 
    } 
} 

Htmlの

.then`使用する方法
<div ng-model="form.recaptcha" 
    size="captcha.size" 
    vc-recaptcha theme="'light'" 
    key="captcha.modelKey" 
    on-create="captcha.setWidgetId(widgetId)" 
    on-success="captcha.setResponse(response)" 
    on-expire="captcha.cbExpiration()" 
    required> 
</div> 

<p ng-show="!form.recaptcha" class="error">Please resolve the captcha</p> 
+0

私のために完全に働いた。ありがとうGaurav – Raghu

関連する問題

 関連する問題