【问题标题】:Google Cloud Endpoint with Angular2带有 Angular2 的谷歌云端点
【发布时间】:2016-05-03 15:18:30
【问题描述】:

我在后端使用 app-engine,并使用 Google Cloud Endpoints 为前端公开 API。前端使用Angular2。

我已经按照 here 描述的策略用于 javascript(或 here 用于 Angular1),这非常有效,但目前不能很好地与 Angular2 融合,因为它不是基于 Observable 的,没有包裹在服务等

在 distinctlyTyped 上,我找到了 Google Sign-In API 的 these 类型定义,但仅用于身份验证。

如果没有找到更好的策略,我最终会为 Gapi 编写一个包装服务,但也许有人有更好的方法?

【问题讨论】:

  • 布伦特,你链接的问题是关于 Http 的。我的问题是关于 Google Cloud Endpoint。
  • 我的错,我以为是关于 Angular2。我撤回了接近投票。我建议您添加有关特定问题的更多细节,而不是更好方法的广泛问题。
  • 关于这个特定项目的任何更新?你最终使用的是包装服务吗?

标签: javascript google-app-engine angular google-cloud-endpoints


【解决方案1】:

你用 Promise 怎么样?

也许.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);
                    });
            }
        );
}

也许.component.ts

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    • 1970-01-01
    相关资源
    最近更新 更多