使用带有Angular中的mergeMap的管道执行订单 [英] enforce order using pipe with mergeMap in Angular

查看:160
本文介绍了使用带有Angular中的mergeMap的管道执行订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular的新手,因此绊脚石. getIds返回一个ID数组,然后我们为每个ID创建一个Observable(getNames).

I'm a newbie to Angular and stumbling with this. getIds returns an array of Ids and then we create an Observable(getNames) for each of these Ids.

interface Name{
    "Id": string;
    "": string;
    "cve_link": string;
    "cve_description": string;
    "cve_applications": string;
    "cve_hosts": string;
    }
export interface Vulns extends Array<Vuln>{}

getIds(): void {
 this.cvetservice
     .getIds().pipe(
     mergeMap(names => this.getNames(this.ids)),
     mergeMap(names => names),
     toArray()
     )
}

getNames(data: Ids):Observable<any[]> {
 return this.http
    .post(url,data)
    .pipe(map(({ Results }: any) => Results[0].results.map(item => ({Id: item.Id, Name: item.Name }))));
    }

第133行mergeMap(names => names)无法编译(以下错误).

The line 133 mergeMap(names => names) fails to compile (error below).

ERROR in src/app/mcomponent.ts(133,19): error TS2345: Argument of type '(names: Name) => Name' is not assignable to parameter of type '(value: Name, index: number) => ObservableInput<{}>'.
Type 'Name' is not assignable to type 'ObservableInput<{}>'.
Type 'Name' is not assignable to type 'Iterable<{}>'.
Property '[Symbol.iterator]' is missing in type 'Name'.
src/app/mcomponent.ts(138,28): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.

有人可以帮我弄清楚我在做什么错吗?

Can someone help clarify what I'm doing wrong here?

推荐答案

乍一看您的代码.这里是问题

At first Glance of your code. here are the issues

getIds(): Observable<any[]> {
 return this.cvetservice
     .getIds().pipe(
     mergeMap(names => this.getNames(this.ids)),
     mergeMap(names => names),
     toArray()
     )
}

getNames(data: Ids):Observable<any[]> {
 return this.http
    .post(url,data)
    .pipe(map((Results : any) => Results[0].results.map(item => ({Id: item.Id, Name: item.Name }))));
    }

提供JSON响应,然后stackblitz将增加更多价值.

Provide the JSON response and stackblitz will add more value.

这篇关于使用带有Angular中的mergeMap的管道执行订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆