Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何正确地在角度服务中实现这一点?_Angular_Typescript_Rxjs_Angular6 - Fatal编程技术网

Angular 如何正确地在角度服务中实现这一点?

Angular 如何正确地在角度服务中实现这一点?,angular,typescript,rxjs,angular6,Angular,Typescript,Rxjs,Angular6,我为Woocommerce找到了一个API库,并试图将其集成到Angular中 对于获取类别,似乎需要这一行 const json = await WooWorker.getCategories(); 我的服务如下所示: import { WooWorker } from "api-ecommerce"; GetAllUsers(): Observable<any> { return this.http.get(`${BASEURL}/categories`);

我为Woocommerce找到了一个API库,并试图将其集成到Angular中

对于获取类别,似乎需要这一行

const json = await WooWorker.getCategories();
我的服务如下所示:

 import { WooWorker } from "api-ecommerce";

  GetAllUsers(): Observable<any> {
    return this.http.get(`${BASEURL}/categories`);
  }
从“api电子商务”导入{WooWorker};
GetAllUsers():可观察{
返回这个.http.get(`${BASEURL}/categories`);
}
我需要替换此部分
返回此.http.get(
${BASEURL}/categories

使用此
const json=await woowerner.getCategories()因为API使用第二种方法。如何正确使用observable?

GetAllUsers():observable{
GetAllUsers(): Observable<any> {
   return WooWorker.getCategories();
  }

返回WooWorker.getCategories(); }

按照上面给出的方法尝试,从中返回数据

您可以用这种方式写入数据

import { WooWorker } from "api-ecommerce";
import { Observable, of } from 'rxjs';

async GetAllUsers(): Observable<any> {
  const json = await WooWorker.getCategories();
  return of(json);
}
从“api电子商务”导入{WooWorker};
从'rxjs'导入{可观察的};
异步GetAllUsers():可观察{
const json=await woowerner.getCategories();
返回(json);
}

of
是一个RxJS运算符,它将输入转换为可观察的。

感谢您的回复。它能与这种API一起工作吗?我问这个问题是因为API提到了react native,但是react导入的文件看起来像简单的JS。如果它返回json,那么你需要调用你的观察者函数来获取json谢谢你的回复。它会与github.com/inspireui/api-ecommerce/tree/master/src这种api一起工作吗?我这样问是因为API提到了react native,但react导入的文件看起来像简单的JS应该有用。因为您必须通过angular项目中的某个NPM包安装它。所以不调用angular的http模块不会导致任何问题?不,不会导致任何问题。先试试看,看起来你想试试。使用(WooWorker.getCategories())中的
延迟(()=>WooWorker.getCategories())