我正在尝试为我的Angular 2应用实施简单的Google身份验证。有没有办法在service.ts中的gapi中实现google的https://apis.google.com/js/api.js脚本?
当我尝试提供服务时出现编译错误。但是当我键入一些导致节点刷新的任意空格时,它会提供一个工作站点。
我看到在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...
答案 0 :(得分:1)
在类顶部声明gapi变量
declare var gapi:any;