2

I have Angular2 application with component which logs in user. Immediate after user is logged in, I route to some page, but I get several errors in console:

Uncaught TypeError: Cannot read property 'style' of null
    at G_ (cb=gapi.loaded_1:91)
    at H_.<anonymous> (cb=gapi.loaded_1:94)
    at Function.<anonymous> (cb=gapi.loaded_0:155)
    at run (vendor.js:99284)
    at runIfPresent (vendor.js:99313)
    at onGlobalMessage (vendor.js:99353)
    at ZoneDelegate.invokeTask (vendor.js:81254)
    at Zone.runTask (vendor.js:81130)
    at ZoneTask.invoke (vendor.js:81324)

in apis.google.com: window.document.getElementById((c?"not_signed_in":"connected")+a.El).style.display="none";

Also this happens if user log in, navigate to random page and then logout from Chrome.

Is there any event on gapi or gapi.auth2 that disconnect listeners so I can avoid errors. I think this should happened on ngOnDestroy. Or maybe configuration that should say 'after render SingIn button, leave it alone'.

I think problem is because I use gapi.signin2.render. The closes topic is this, but I can not use solution "Just hide element don't remove it".

Edited:

If it helps, this is my render code:

ngAfterViewInit()
{
    gapi.load("auth2", () =>
    {
        gapi.auth2.init({
            client_id: "************"
        });
        gapi.signin2.render(
            this.googleLoginButtonId,
            {
                onsuccess: (user) => { this.onGoogleLoginSuccess(user); },
                onfailure: (error) => { this.onGoogleLoginError(error); },
                scope: this.scopes.join(" ")
            });
    });
}
Community
  • 1
  • 1
Makla
  • 9,899
  • 16
  • 72
  • 142
  • 1
    I post issue on [GitHub](https://github.com/google/google-api-javascript-client/issues/281). – Makla Feb 22 '17 at 15:54

0 Answers0