2

I'm trying to implement a simple google authentication for my Angular 2 app. Is there a way to implement google's https://apis.google.com/js/api.js script inside of gapi in a service.ts?

I get a compilation error when I try to ng serve it. But when I type some arbitrary spaces which causes node to refresh, it serves up a working site.

I see that var gapi exists inside the api.js script ,but is there a way to extract that variable into 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 Answer 1

1

declare the gapi variable on the top of the class

declare var gapi:any;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.