简体   繁体   English

带有Angular2的Google Cloud Endpoint

[英]Google Cloud Endpoint with Angular2

I am using app-engine on the backend, with Google Cloud Endpoints to expose APIs for the front end. 我在后端使用app引擎,并通过Google Cloud Endpoints公开前端的API。 The Front end is using Angular2. 前端使用Angular2。

I have followed the strategy described here for javascript (or here for Angular1), and this pretty much works but does not blends in well with Angular2 at the moment as it is not Observable based, not wrapped in a service etc. 我已经按照这里描述的针对javascript的策略(或这里针对Angular1的策略)进行了描述,并且这几乎可以正常工作,但由于它不是基于Observable的,也没有包装在服务中,因此目前无法与Angular2很好地融合。

On DefinitelyTyped, I found these type definitions for Google Sign-In API but is only for authentication. 在DefinitelyTyped上,我找到了Google登录API的这些类型定义,但仅用于身份验证。

If no better strategy is identified, I'll end up writing a wrapper service for Gapi, but maybe someone has a better approach? 如果没有找到更好的策略,我最终将为Gapi写一个包装器服务,但是也许有人有更好的方法?

How about you use Promise? 您如何使用Promise?

maybe.service.ts maybe.service.ts

function getPerson:  Promise<FooBarResponse>(){
  var arg:ArgFooBarPeople = new ArgFooBarPeople();
  return new Promise<FooBarResponse>(
            (resolve,reject) =>
            { gapi.client["foobarapi"]["person"].all(arg).execute(
                    (response:any)=>{
                        resolve(response);
                    });
            }
        );
}

maybe.component.ts maybe.component.ts

function load(){
    this._foobarService.getPerson()then(
             (response:FooBarResponse):void =>{
                    console.log(response);
                    this.fooBarResponse = response;
        }).catch( (error)=>{this.error="error !!"});
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM