объединить карту с трубой в Angular - PullRequest
0 голосов
/ 10 ноября 2018

Я новичок; пожалуйста, потерпите меня.

Мне нужно получить список идентификаторов Id => this.getIds () и получить их имена => getNames (id) для каждого идентификатора в списке идентификаторов, используя mergeMap (). Может кто-нибудь проверить, что я делаю неправильно ниже (не компилируется)?

interface Id{
            "Id": string;
            "Name": string;
}
export interface Ids extends Array<Id>{}

в myservice.ts

 getIds():Ids {
  return this.http
  .post(url1, '')
  .pipe(map(({ Ids}: Ids) => Ids.map(item => ({Id: item.Id }))));
 }
getNames():Observable<any[]> {
 return this.http
    .post(url2, '')
    .pipe(map(({ Names }: any) => Names.map(item => ({Sid: item.Id, Name: item.Name }))));
}

в mycomponent.ts,

getIds(): void {
 this.myservice
  .getIds.pipe(
  mergeMap(id => this.getNames(id)),
  mergeMap(names => names),
  toArray()
  )
}
getNames(): void {
 this.myservice
 .getNames(ids)
 .subscribe(val => this.data = val);
}

ERROR in src/app/myservice.ts(24,5): error TS2322: Type 'Observable<any>' is not assignable to type 'Ids'.
Property 'includes' is missing in type 'Observable<any>'.
src/app/myservice.ts(26,17): error TS2459: Type 'Ids' has no property 'Ids' and no string index signature.
src/app/mycomponent.ts(128,20): error TS2339: Property 'pipe' does not exist on type '() => Ids'.
src/app/mycomponent.ts(129,35): error TS2345: Argument of type '{}' is not assignable to parameter of type 'Ids'.
Property 'includes' is missing in type '{}'. src/app/mycomponent.ts(130,19): error TS2345: Argument of type '(vulns: {}) => {}' is not assignable to parameter of type '(value: {}, index: number) => ObservableInput<{}>'.
Type '{}' is not assignable to type 'ObservableInput<{}>'.
Type '{}' is not assignable to type 'Iterable<{}>'.
Property '[Symbol.iterator]' is missing in type '{}'.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...