首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >订阅switchMap RXJS

订阅switchMap RXJS
EN

Stack Overflow用户
提问于 2019-06-05 17:42:52
回答 1查看 116关注 0票数 0

我在下面的代码中发现2个语法错误:

代码语言:javascript
复制
handleTypeahead = (text$: Observable<string>) => {
    text$.pipe(
      distinctUntilChanged(),
      debounceTime(500),
      .tap((term) => this.target = text$),
    // tap((term) => console.log("handleTypeahead", term)),
    // tap((term) => this.onTypeahead.emit(term)),
    /*map((term: string) => [])*/
    /*map((term: string) => term === '' ? [] : this.data)*/
    .switchMap(term => term === '' ? [] : this.data)
  ).subscribe((term) => this.onTypeahead.emit(term))

  }

1)by debounceTime -“期望的表达式”。2)by .subscribe -“未解析的函数或方法subscribe()”我在没有使用pipe操作符的情况下尝试了这一点,但也有语法错误,这是RXJS的新手,但在正确实现这一点上有很多问题。v2:

代码语言:javascript
复制
handleTypeahead = (text$: Observable<string>) => {
    text$
      distinctUntilChanged(),
    debounceTime(500),
      .tap((term) => this.target = text$),
    // tap((term) => console.log("handleTypeahead", term)),
    // tap((term) => this.onTypeahead.emit(term)),
    /*map((term: string) => [])*/
    /*map((term: string) => term === '' ? [] : this.data)*/
    .switchMap(term => term === '' ? [] : this.data)
      .subscribe((term) => this.onTypeahead.emit(term))
  }

在这里我得到了just error num#2任何感谢的帮助(当然会向上投票)

EN

回答 1

Stack Overflow用户

发布于 2019-06-05 17:51:37

.tap.switchMap正常工作之前删除这些点:

代码语言:javascript
复制
text$.pipe(
  distinctUntilChanged(),
  debounceTime(500),
  tap(term => this.target = text$),
  switchMap(term => term === '' ? [] : this.data)
).subscribe(term => this.onTypeahead.emit(term));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56457998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档