AngularJS and google cloud endpoint: walk through needed

♀尐吖头ヾ 提交于 2019-11-30 05:28:43

For loading Google Javascript Library with AngularJs, the callback function passed to onLoad of Google Javascript Library is the function that bootstrap AngularJS, like this:

This goes to the final of html file:

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

Then, in <head> section you bootstrap angular like this:

<script type='text/javascript'>

function startApp() {

    var ROOT = 'http://<yourapi>.appspot.com/_ah/api';
    gapi.client.load('myapifromgoogleendpoint', 'version1', function() {
        angular.bootstrap(document, ["myModule"]);
    }, ROOT);
}

</script>

As described by Kenji, you also need to remove ng-app directive from your html.

Regarding the callback - In order to access an Angular controller you need to use an injector (http://docs.angularjs.org/api/AUTO.$injector)

Simply create a global callback function, and then get reference to the controller from it like this:

window.callbackFunction() {
  injector = angular.element(document.getElementById('YourController')).injector()
  injector.invoke(function ($rootScope, $compile, $document) {
    $rootScope.variable = "stuff you want to inject";
  })
}

In this example I'm injecting the data to the rootScope, but this will also work for a specific controller scope (just inject $scope instead)

Can't help with the second question as I'm not familiar with gapi, though making auth2 calls from angularjs is quite straight forward.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!