angularjs - How to properly load gmail api to angular 2 app -


i kind of new angular 2 ill try explain requirement in details. app build has login page (/login) , has settings page (/settings).

when user access login page gapi var initialized user logs in app.

once user in has settings page. issue starts when user refresh page, when happens gapi var no longer recognized , become undefined. though gapi library not getting loaded , therefore fails.

i placed following code in app index.html file

<script type="text/javascript">   // client id , api key developer console   var client_id = '***.apps.googleusercontent.com';    // array of api discovery doc urls apis used quickstart   var discovery_docs = ["https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest"];    // authorization scopes required api; multiple scopes can   // included, separated spaces.   var scopes = 'https://www.googleapis.com/auth/gmail.readonly';    /**    *  on load, called load auth2 library , api client library.    */   function handleclientload() {       console.log("handleclientload")     gapi.load('client:auth2', initclient);   }    /**    *  initializes api client library , sets sign-in state    *  listeners.    */   function initclient() {     gapi.client.init({       discoverydocs: discovery_docs,       clientid: client_id,       scope: scopes     }).then(function () {       // listen sign-in state changes.       console.log("client init");       gapi.auth2.getauthinstance().issignedin.listen();        // handle initial sign-in state.       //updatesigninstatus(gapi.auth2.getauthinstance().issignedin.get());      });   }   </script>  <script async defer src="https://apis.google.com/js/api.js"         onload=this.onload=function(){};handleclientload();         onreadystatechange="if (this.readystate === 'complete') this.onload()";>  </script> 

to conclude how can load gapi module handle above refresh scenario?

i tried work solution best way wait 3rd-party js library finish initializing within angular 2 service? didnt work, gapi still undefined.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -