您能够从组件中调用角为6的SOAP调用吗?
如果是这样的话,您可以给出一个简单调用和返回处理对象的例子吗?
发布于 2019-02-23 18:31:56
只要您可以使用Http来访问API,就可以使用角的HttpClient库来访问它。
例如,您可以从这里的文档开始:https://angular.io/guide/http#httpclient
或者我这里有一个简单的堆栈闪电战:https://stackblitz.com/edit/angular-simple-retrieve-deborahk
接口
// Define the shape of the incoming data
export interface Product {
productId: number;
productName: string;
productCode: string;
}服务
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);
}
}https://stackoverflow.com/questions/54844618
复制相似问题