srv
srv

Reputation: 440

AngularJS Google App Engine API Load Error

When a Google App Engine endpoint API is called immediately once the page is loaded, the following error is thrown. I need to wait for few seconds to call the API.

Then is same when the page is reloaded by some other means, say called from an other page etc.

I have tried adding a callback to call the API after few milliseconds $timeout(queryCallback, 100, false); The results are the same.

Is this a AngularJS error or resource load error? How to solve the error, please share your comments.

angular-1.2.16.min.js:89 TypeError: Cannot read property 'queryInfo' of undefined
  at h.$scope.queryInfoAll (controllers.js:641)
  at $scope.queryInfo (controllers.js:616)
  at angular-1.2.16.min.js:119
  at e (angular-1.2.16.min.js:37)
  at angular-1.2.16.min.js:40

controllers.js:641

gapi.client.database.queryInfo().execute(function (resp) { }

Upvotes: 0

Views: 102

Answers (1)

HammondSuisse
HammondSuisse

Reputation: 143

In looking at the Java endpoints example here, you use endpoints in javascript by initializing via a call to

<script src="https://apis.google.com/js/client.js?onload=init"></script>

...which calls the JS method named "init", which is a method name of your choosing. This is, however, a plain ole JS method that is unaware of the AngularJS lifecycle. In your init method, it seems you explicitly init your specific endpoint library, as in:

gapi.client.load(apiName, apiVersion, callback, apiRoot);

So, in your "run()", you may have to ask if "gapi" exists and defer until it is. You would then call "gapi.client.load()" with the callback function set.

Upvotes: 1

Related Questions