Even though I can pass a scope value to the key
attribute in the vc-recaptcha
directive, it is initialized only once, right after the recaptcha widget is created. This is enough for cases, where the key is static and hardcoded. Currently I am dealing with a site, which retrieves the site key from an external source. When the key is finally retrieved (by the $http service), the initialization process is already finished and the site key bound to the widget cannot be modified anymore.
I have dived into the code and localized the core of my headaches:
// Remove this listener to avoid creating the widget more than once.
removeCreationListener();
It is not bad, because we do not want an another watcher hanging in memory forever, but it destroys the possibility of modifying the site key.
I have created a solution which accepts both string and promise as a key. The recaptcha widget is not initialized until the promise is resolved, thus we are free to pass the key when it is available.
It works very well, so I think I can share with it in a pull request.