【问题标题】:Property 'filter' does not exist on type 'Observable<>'Observable<> 类型上不存在属性 'filter'
【发布时间】:2018-11-21 08:49:50
【问题描述】:
enter code here


    getHospital(term: string = null): Observable<Hospitals[]> {
    let items = this.getHospitals1();
    if (term) {
      items = items.filter(x => x.name.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1);

    }
    return items.pipe(delay(500));;
  }



getHospitals1() : Observable<Hospitals[]>{

     return this.http.get<Hospitals[]>('https://my-json-server.typicode.com/monsterbrain/FakeJsonServer/hospitals')

   }

这里我添加过滤器时出错 它是使用 ng-select 的下拉列表的代码。它基于基于文本的搜索 这里我使用 angular7 和 rxjs 6

【问题讨论】:

    标签: angular rxjs angular6 rxjs6 angular-ngselect


    【解决方案1】:

    要使用filter 运算符,您需要在pipe() 中使用它:

    import { filter } from 'rxjs/operators';
    
    ...
    
    if (term) {
      items = items.pipe(
        filter(x => x.name.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1),
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2017-01-23
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      • 2016-10-31
      • 2017-10-20
      • 2018-10-16
      相关资源
      最近更新 更多