Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Google Calendar and Async API calls in angular

$
0
0

Hello Ionic!
This might be more of an angular issue, but I’m trying out Ionic as a hybrid dev stack.

I’m working with data from a google calendar. As some of you may know the Google Calendar API is asynchronous. According to the API things happen in this order:

1) Call the api: <script src="https://apis.google.com/js/client.js?onload=init"></script>
2) Using “?” query call your function to load the calendar api:

function init() {
gapi.client.setApiKey(Key);
gapi.client.load('calendar', 'v3', listUpcomingEvents);
} //this function can live anywhere

3) The gapi.client.load function, if successful, then should call your calendar request e.g., the listUpcomingEvents() which then should get your data.

Using plain javascript I can sequence the events properly. With angular it’s step 3 where I run into issues. The third argument of gapi.client.load('calendar', 'v3', listUpcomingEvents) won’t work with an angular function inside a controller, or a service as far as I know.

So I am only using: gapi.client.load('calendar', 'v3’).

Without the function argument you cannot guarantee the calendar api will be ready when you make your data request. Most times it returns undefined.

I supposed what I need is to be able to call a function outside of a controller but still scoped to the view. I haven’t found a working solution, especially inside Ionic.

Is there a solution to this?


Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>