【发布时间】:2020-02-09 08:10:01
【问题描述】:
我找到了一个用于 Woocommerce 的 API 库并尝试将其集成到 Angular 中。
为了获取类别,看起来需要这一行。
const json = await WooWorker.getCategories();
我的服务如下所示:
import { WooWorker } from "api-ecommerce";
GetAllUsers(): Observable<any> {
return this.http.get(`${BASEURL}/categories`);
}
我需要替换这部分return this.http.get(${BASEURL}/categories);
使用此const json = await WooWorker.getCategories();,因为 API 使用第二种方式。用 observable 做这件事如何正确?
【问题讨论】:
-
看起来你想convert a Promise to an Observable。使用
from(WooWorker.getCategories())或defer(() => WooWorker.getCategories())。
标签: angular typescript rxjs angular6