这里的语法有什么问题?mergeMap(names => names),
getIds(): void {
this.myservice
.getIds.pipe( mergeMap(id => this.getNames(id)),
mergeMap(names => names), toArray() )
} myservce.ts具有以下特性:
getIds():Observable<Ids>{
const url = 'http://localhost:4000';
return this.http
.post(url, '')
.map(({ Ids }: any) => Ids.map(item => ({Id: item.Id,
Name: item.Name }))) as Observable<Ids>;
}
getNames(data: Ids):Observable<any[]> {
const url ='http://localhost:5000';
return this.http
.post(url,data)
.pipe(map(({ Results }: any) => Results[0].results.map(item => ({Id: item.ID, Name: item.Name }))));
}编译器错误是(作为一个新手,我不能确定):
ERROR in src/app/cvetable/mcomponent.ts(132,19): error TS2345:
Argument of type '(names: {}) => {}' is not assignable to parameter
of type '(value: {}, index: number) => ObservableInput<any[]>'.
Type '{}' is not assignable to type 'ObservableInput<any[]>'.
Type '{}' is not assignable to type 'Iterable<any[]>'.
Property '[Symbol.iterator]' is missing in type '{}'.发布于 2018-11-11 03:05:45
您的服务中的getIds方法存在严重错误:
它应该是这样的。由于您使用的是HttpClient,而您的eg在Angular 7中使用Rxjs 6+,因此您必须将.pipe调用链接到您的可观察值,以便对其应用运算符。在.pipe调用中,您可以放置一个逗号分隔的运算符列表:
getIds(obj):Observable<Ids>{
return this.http
.post(this.url, obj)
.pipe(
map((Ids: any) => Ids.map(item => ({Id: item.Id, Name: item.Name }) ) )
)
}这是一个修复了错误的。
https://stackoverflow.com/questions/53242276
复制相似问题