title: Google Sign-in Cannot read property 'load' of undefined
body: <p>I attempting to create a Google Sign-in in an Angular application, but I keep getting the following error: </p>
  
  <blockquote>
    <p>Cannot read property 'load' of undefined</p>
  </blockquote>
  
  <p>I actually had this working just an hour ago, but now it seems to be having a loading issue - I'm pretty sure something is out of sync somewhere, but I'm not sure what I can do about it?</p>
  
  <p>Just for clarity, my app does not load onto the login page from start, I navigate to it afterwards using the address bar in Chrome (don't know if that would make a difference). I have got the right client id in there, I just replaced it for this question for security.</p>
  
  <p><strong>login.component.ts</strong></p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  
  @Component({
    selector: 'app-login',
    templateUrl: './login.component.html',
    styleUrls: ['./login.component.css']
  })
  
  export class LoginComponent implements OnInit {
  
    constructor() { }
  
    public auth2: any;
    user: string;
    gapi: any;
  
    public googleInit() {
      this.gapi.load('auth2', () =&gt; {
        this.auth2 = this.gapi.auth2.init({
          client_id: 'client_id.apps.googleusercontent.com',
          cookiepolicy: 'single_host_origin',
          scope: 'profile email'
        });
        this.attachSignin(document.getElementById('googleBtn'));
      });
    }
  
    public attachSignin(element) {
      this.auth2.attachClickHandler(element, {},
        (googleUser) =&gt; {
  
          let profile = googleUser.getBasicProfile();
          console.log('Token || ' + googleUser.getAuthResponse().id_token);
          console.log('ID: ' + profile.getId());
          console.log('Name: ' + profile.getName());
          console.log('Image URL: ' + profile.getImageUrl());
          console.log('Email: ' + profile.getEmail());
          //YOUR CODE HERE
          this.user = "";
  
        }, (error) =&gt; {
          alert(JSON.stringify(error, undefined, 2));
        });
    }
  
    ngAfterViewInit(){
      this.googleInit();
    }
  
    ngOnInit() {
    }
  
  }
  </code></pre>
  
  <p><strong>login.component.html</strong></p>
  
  <pre><code>&lt;div id="googleBtn"&gt;Login w/ Google&lt;/div&gt;
  </code></pre>