Simple filter on array of RXJS Observable

后端 未结 4 827
独厮守ぢ
独厮守ぢ 2020-12-12 19:21

I am starting my project with Angular2 and the developers seem to recommend RXJS Observable instead of Promises.

I have achieved to retrieve a list of elements (epic

4条回答
  •  萌比男神i
    2020-12-12 19:42

    original answer with a fix: Observables are lazy. You have to call subscribe to tell an observable to send its request.

      getEpic(id:number) {
        return this.getEpics()
               .filter(epic => epic.id === id)
               .subscribe(x=>...);
      }
    

    Update to Rxjs 6:

    import {filter} from 'rxjs/operators';
    
    getEpic(id:number) {
            return this.getEpics()
                   .pipe(filter(epic => epic.id === id))
                   .subscribe(x=>...);
          }
    

提交回复
热议问题