我正在使用Angular(9)Powered Bootstrap(ng-bootstrap 6.1),并为ngbTypeahead提供了Observable
search = (text$: Observable<string>) => {
return text$.pipe(
debounceTime(200),
distinctUntilChanged(),
// switchMap allows returning an observable rather than maps array
switchMap((searchText) => {
if (!searchText || searchText.trim().length < 3) {
// when the user erases the searchText
return EMPTY;
} else {
// get a list of dealer reps
return this.myService.getKeyValues(searchText);
}
})
, catchError((error) => of(this.myService.postErrorMessage(error)))
);
}
我需要通过将每个IKeyValue项目映射到它的item.value属性来将this.myService.getKeyValues的输出从Observable
我如何使用rxjs 6.5.5修改上面的代码来做到这一点?
答案 0 :(得分:1)
在switchMap之后,您可以放置一个moving metadata to the front运算符,进行所需的转换并返回新值。
我认为这将符合这些原则。请注意,返回值中的map()是不同的。
curl --header "Content-Type: application/json" \
--request POST \
--data '{"username":"xyz", "preference":"123"}' \
http://localhost:3000/mih/search
}