2017-12-28 34 views
1

私はAngular 2アプリで簡単なGoogle認証を実装しようとしています。 googleのhttps://apis.google.com/js/api.jsスクリプトをservice.tsのgapiの中に実装する方法はありますか?角度サービスでgoogleのapi.jsを使用します.ts

サービスを提供しようとすると、コンパイルエラーが発生します。しかし、ノードをリフレッシュさせるような任意のスペースを入力すると、作業現場を提供します。

私は、variがapi.jsスクリプト内に存在することを確認しますが、その変数を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... 

答えて

1

クラス

declare var gapi:any; 
の上にGAPI変数を宣言
関連する問題