首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角6简单SOAP Api调用

角6简单SOAP Api调用
EN

Stack Overflow用户
提问于 2019-02-23 18:15:58
回答 1查看 2.8K关注 0票数 0

您能够从组件中调用角为6的SOAP调用吗?

如果是这样的话,您可以给出一个简单调用和返回处理对象的例子吗?

EN

回答 1

Stack Overflow用户

发布于 2019-02-23 18:31:56

只要您可以使用Http来访问API,就可以使用角的HttpClient库来访问它。

例如,您可以从这里的文档开始:https://angular.io/guide/http#httpclient

或者我这里有一个简单的堆栈闪电战:https://stackblitz.com/edit/angular-simple-retrieve-deborahk

接口

代码语言:javascript
复制
// Define the shape of the incoming data
export interface Product {
  productId: number;
  productName: string;
  productCode: string;
}

服务

代码语言:javascript
复制
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError, tap, map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class ProductService {
  // To try error handling, change this URL to product instead of products
  private productUrl = 'assets/products/products.json';

  constructor(private http: HttpClient) { }

  getProducts(): Observable<Product[]> {
    // Use Angular's HttpClient library to issue a GET request
    // OPTIONAL: Pipe it through operators for debugging, data
    // manipulation, or error handling
    return this.http.get<Product[]>(this.productUrl).pipe(
      tap(data => console.log('All: ' + JSON.stringify(data))),
      catchError(error => this.handleError<Product[]>(error, 'get', []))
    );
  }

  // To try out the error handling, change the Url above
  private handleError<T>(err: HttpErrorResponse, operation = 'operation', result?: T) {
    // in a real world app, we may send the server to some remote logging infrastructure
    // instead of just logging it to the console
    let errorMessage = '';
    if (err.error instanceof ErrorEvent) {
      // A client-side or network error occurred. Handle it accordingly.
      errorMessage = `An error occurred: ${err.error.message}`;
    } else {
      // The backend returned an unsuccessful response code.
      // The response body may contain clues as to what went wrong,
      errorMessage = `Server returned code: ${err.status}, error message is: ${err.message}`;
    }
    console.error(errorMessage);
    return throwError(errorMessage);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54844618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档