【问题标题】:Using google's api.js in angular service.ts在 angular service.ts 中使用谷歌的 api.js
【发布时间】:2017-12-28 20:30:40
【问题描述】:

我正在尝试为我的 Angular 2 应用程序实施简单的 google 身份验证。有没有办法在 service.ts 的 gapi 内实现 google 的 https://apis.google.com/js/api.js 脚本?

当我尝试 ng 服务时出现编译错误。但是当我输入一些导致节点刷新的任意空格时,它会提供一个工作站点。

我看到 api.js 脚本中存在 var gapi ,但是有没有办法将该变量提取到 ts 中。

import {Injectable} from '@angular/core';
import * as jQuery from 'jquery';


@Injectable()
export class AuthService {
  testFunction() {
    jQuery.getScript("https://apis.google.com/js/api.js", handleClientLoad);
    var CLIENT_ID = 'SECRET';
    var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest"];

    var SCOPES = 'https://www.googleapis.com/auth/youtube.readonly';
    var authorizeButton = document.getElementById('authorize-button');
    var signoutButton = document.getElementById('signout-button');
    var signedInMenu = document.getElementById('signed-in-menu');
    /**
     *  On load, called to load the auth2 library and API client library.
     */
    function handleClientLoad() {
      gapi.load('client:auth2', initClient);
    }

}...more code that also calls gapi...

【问题讨论】:

    标签: javascript node.js angular google-api


    【解决方案1】:

    在类的顶部声明gapi变量

    declare var gapi:any;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2022-07-05
      • 2019-07-21
      相关资源
      最近更新 更多