NodeJS [SOLVED]: Using google's api.js in angular service.ts

NodeJS [SOLVED]: Using google's api.js in angular service.ts

Home Forums Scripting NodeJS Tutorials NodeJS [SOLVED]: Using google's api.js in angular service.ts

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #245841

    Cloudy Point
    Keymaster

    QuestionQuestion

    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...
    

    #245842

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    declare the gapi variable on the top of the class

    declare var gapi:any;
    

    Source: https://stackoverflow.com/questions/48013971/using-googles-api-js-in-angular-service-ts
    Author: santosh singh
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.