最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

在角度service.ts中使用谷歌的api.js

IT培训 admin 3浏览 0评论

在角度service.ts中使用谷歌的api.js

我正在尝试为我的Angular 2应用实施简单的Google身份验证。有没有办法在service.ts中的gapi中实现google的.js脚本?

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

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

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


@Injectable()
export class AuthService {
  testFunction() {
    jQuery.getScript(".js", handleClientLoad);
    var CLIENT_ID = 'SECRET';
    var DISCOVERY_DOCS = [""];

    var SCOPES = '.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...
回答如下:

在类的顶部声明gapi变量

declare var gapi:any;

在角度service.ts中使用谷歌的api.js

我正在尝试为我的Angular 2应用实施简单的Google身份验证。有没有办法在service.ts中的gapi中实现google的.js脚本?

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

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

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


@Injectable()
export class AuthService {
  testFunction() {
    jQuery.getScript(".js", handleClientLoad);
    var CLIENT_ID = 'SECRET';
    var DISCOVERY_DOCS = [""];

    var SCOPES = '.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...
回答如下:

在类的顶部声明gapi变量

declare var gapi:any;
发布评论

评论列表 (0)

  1. 暂无评论