VividCortex / angular-recaptcha

AngularJS directive to add a reCaptcha widget to your form
http://vividcortex.github.io/angular-recaptcha/
MIT License
496 stars 257 forks source link

Feature: Hook into onload callback #32

Closed TheSharpieOne closed 8 years ago

TheSharpieOne commented 9 years ago

Since the onload callback function on the API script's URL should be the callback in the service (vcRecapthaApiLoaded), it would be nice to allow for other callbacks so the dev can know when its been called. There should be a way to have a callback function called when recaptcha is loaded and angular-recaptcha is ready.

var app = angular.module('myModule', ['vcRecaptcha']);

app.config(['vcRecaptchaServiceProvider', function(vcRecaptchaServiceProvider) {
    vcRecaptchaServiceProvider.onLoad.push(function(recaptcha){
        // recaptcha is loaded, do something
    });
}]);

Here, onLoad is an array of functions, when the vcRecapthaApiLoaded callback is called, it would call the onLoad functions.

Current work-around: Set the API script URL's onload callback to your custom function (with the logic you need) then manually call vcRecapthaApiLoaded from your function to notify angular-recaptcha that recaptcha is loaded.

TheSharpieOne commented 8 years ago

This was pretty much resolved in #105.

One can now do this in their own code:

vcRecapthaApiLoaded = vcRecapthaApiLoaded || [];
vcRecapthaApiLoaded.push(myCustomCallbackFunction);