У меня есть наблюдаемое userInput$
, которое возвращает потоки данных каждые N секунд, когда пользователь вводит данные для ввода.Я хочу получить последний ввод и передать его в качестве параметра функции service.search(x)
, которая будет возвращать другую наблюдаемую со списком данных.
this.userInput$
.pipe(withLatestFrom(x => this.service.search(x)))
.subscribe(x => {
//do not receiving any data here
});
Любой, почему мой код не работает?
My userInput$
return a string
my this.service.search(x)
возвращает массив - это то, что я хочу получить в результате.
ОБНОВЛЕНИЕ:
const example = this.userInput$
.pipe(withLatestFrom(x => this.service.search(x)),
map(([userInput, searchOutput ]) => { // error here
return {query: userInput, result: searchOutput};
})
);
[userInput, searchOutput]
-получение ошибки [ts] Type 'Observable<GetSearch[]>' is not an array type. [2461]
Только для теста изменено this.service.search(x)
на of(x)
const example = this.userInput$
.pipe(withLatestFrom(x => of(x)),
map(([userInput, searchOutput ]) => { // error here
return {query: userInput, result: searchOutput};
})
);
map
, возвращающее ошибку [ts] Type 'Observable<any>' is not an array type. [2461]