Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Angular 2应用程序连接到Google云端点_Angular_Typescript_Google Api_Google Cloud Platform_Google Cloud Endpoints - Fatal编程技术网

从Angular 2应用程序连接到Google云端点

从Angular 2应用程序连接到Google云端点,angular,typescript,google-api,google-cloud-platform,google-cloud-endpoints,Angular,Typescript,Google Api,Google Cloud Platform,Google Cloud Endpoints,我目前正在将一个web应用程序从Angular 1重构为Angular 2,但我很难找到从Angular 2应用程序连接到Google云端点的任何示例 我使用创建Angular 2应用程序。我希望使用来自两个不同服务的endpoints api,因此如果任何建议的答案都考虑到这一点,那就更好了 在Angular 1中,我做了以下操作 在my index.html中: <script> function init() { console.

我目前正在将一个web应用程序从Angular 1重构为Angular 2,但我很难找到从Angular 2应用程序连接到Google云端点的任何示例

我使用创建Angular 2应用程序。我希望使用来自两个不同服务的endpoints api,因此如果任何建议的答案都考虑到这一点,那就更好了

在Angular 1中,我做了以下操作

在my index.html中:

    <script>
        function init() {
            console.log("Initializing Cloud Endpoints..");
            window.init();
        };
    </script>        

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

<script>
  function init() {
    console.log("Init called");

    gapi.client.load('deviceStockApi', 'v1', function(){
      console.log("Cloud Endpoints are now available");
    }, 'https://name-of-my-endpoints-app.appspot.com/_ah/api');
  }
</script>
在Angular 2中,我尝试过

Edit1:我应该注意,我只是想让api为初学者加载。这就是为什么我将所有代码放在下面示例中的index.html文件中。然而,从最佳角度来说,我更喜欢一个具有从Angular 2应用程序启动和使用云端点的最佳实践的解决方案

在my index.html中:

    <script>
        function init() {
            console.log("Initializing Cloud Endpoints..");
            window.init();
        };
    </script>        

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

<script>
  function init() {
    console.log("Init called");

    gapi.client.load('deviceStockApi', 'v1', function(){
      console.log("Cloud Endpoints are now available");
    }, 'https://name-of-my-endpoints-app.appspot.com/_ah/api');
  }
</script>

函数init(){
log(“Init调用”);
load('deviceStockApi','v1',function(){
log(“云端点现在可用”);
}, 'https://name-of-my-endpoints-app.appspot.com/_ah/api');
}
当我运行webapp时,不会调用init函数(没有控制台输出)。但是,脚本似乎已加载


任何关于如何解决此问题的建议都将不胜感激!另外,如果有人从谷歌或其他网站上找到了一些详细的文档,请分享

您是否尝试过在此处颠倒操作顺序?与Angular 1一样,尝试将api.google.com导入移动到init代码块下方