@1backend/ng-client 中文文档教程

发布于 7年前 浏览 23 项目主页 更新于 3年前

1Backend Angular Client

该包可用于调用 1Backend 上的任何服务。

还请检查您的 1Backend 服务的类型安全自动生成的 API,您可能会发现它们使用起来更愉快。

安装:

npm install --save @1backend/ng-client

使用

import { Component, OnInit } from '@angular/core';
import { NgClient } from '@1backend/ng-client';

// This is a working test token.
// You can get your own tokens from 1Backend from your profile page (eg. https://1backend.com/your-name)
const token = '1c61722e-9e0b-461b-9e27-193464b081f9';

@Component({
  selector: 'app-example',
  template: `Response: {{response}} Error: {{error}}`,
  providers: [NgClient]
})
export class ExampleComponent implements OnInit {
  response: string;
  error: any;

  constructor(private ngClient: NgClient) {
    this.ngClient.token = token;
    this.ngClient.call<string>('crufter', 'test', 'get', '/sql-example', {}).then(rsp => {
        this.response = rsp;
      })
      .catch(err => {
        this.error = err;
      });
  }

  ngOnInit() {}
}

1Backend Angular Client

This package can be used to call any service on 1Backend.

Please also check the typesafe autogenerated APIs for your 1Backend services, you might find them more pleasant to use.

Installation:

npm install --save @1backend/ng-client

Usage

import { Component, OnInit } from '@angular/core';
import { NgClient } from '@1backend/ng-client';

// This is a working test token.
// You can get your own tokens from 1Backend from your profile page (eg. https://1backend.com/your-name)
const token = '1c61722e-9e0b-461b-9e27-193464b081f9';

@Component({
  selector: 'app-example',
  template: `Response: {{response}} Error: {{error}}`,
  providers: [NgClient]
})
export class ExampleComponent implements OnInit {
  response: string;
  error: any;

  constructor(private ngClient: NgClient) {
    this.ngClient.token = token;
    this.ngClient.call<string>('crufter', 'test', 'get', '/sql-example', {}).then(rsp => {
        this.response = rsp;
      })
      .catch(err => {
        this.error = err;
      });
  }

  ngOnInit() {}
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文