Angular没有运行数据成功功能

时间:2019-07-09 13:45:52

标签: angular typescript google-oauth google-oauth2

我正在尝试遵循本教程 https://developers.google.com/identity/sign-in/web/sign-in 当我登录时,数据成功不会运行onSignIn()功能。

我将脚本放入此代码

ngOnInit() {
    this.loadScript('https://apis.google.com/js/platform.js');
  }
  public loadScript(url: string) {
    const body = document.body as HTMLDivElement;
    const script = document.createElement('script');
    script.innerHTML = '';
    script.src = url;
    script.async = false;
    script.defer = true;
    body.appendChild(script);
  }

在与之相同的组件类中,

public onSignIn(googleUser) {
    const profile = googleUser.getBasicProfile();
    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
    console.log('Name: ' + profile.getName());
    console.log('Image URL: ' + profile.getImageUrl());
    console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    console.log('hi');
  }
  public signOut() {
    const auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then( () => {
      console.log('User signed out.');
    });

div标签与本教程中的一样,

<div class="g-signin2" data-onsuccess="onSignIn"></div>

0 个答案:

没有答案