AngularJS-ionic-Cloud Endpoints:Cannot read property ‘xxx’ of undefined

Published on:
Last updated:

This post is also available in: 日本語 (Japanese)

When I try to call the API of Cloud Endpoints using AngularJS, I'm getting an error message below.
Cause is that Cloud Endpoints method does not called at the start of service(initialization).

Uncaught TypeError: Cannot read property 'xxx' of undefined

Call the client library

Javascript code below will make sure to to be called "the last" than other code(such as AngularJS and ionic).

<script src=""></script>

Since calling the initialization function "init ()" by "onload = init", you add the following code to the file where you want to use the Cloud Endpoints.
Meaning of the detailed code, please refer to the google Developer Guide link at the end article.

function init() {

Add an initialization process to controller of AngularJS

Add the code like the following to controller or service of AngularJS.
Do not forget to take a "$window" to the argument of the controller and services.

    $window.init = function () {

    $scope.sample_googleendpoints_lib = function () {
        var ROOT = '';
        gapi.client.load('your_api_name', 'v1', function () {
        }, ROOT);

Reference Quote:

No tags for this post.

Kuniyoshi Takemoto is the founder of LLC, and editor of this blog( more and follow me on LinkedIn.