RxJs get value from observable

SuperOrange picture SuperOrange · Jun 3, 2016 · Viewed 76.9k times · Source

In component :

singleEvent$: Observable<Event>;

On init, I get observable

this.singleEvent$ = this._eventService.events$
  .map(function (events) {
    let eventObject = events.find(item => item.id === eventid);
    let eventClass: Event = new Event(eventObject);
    return eventClass;
  });

How can I take current value like event.name ?

Answer

G&#252;nter Z&#246;chbauer picture Günter Zöchbauer · Jun 3, 2016

To get data from an observable, you need to subscribe:

this.singleEvents$.subscribe(event => this.event = event);

In the template you can directly bind to observables using the async pipe:

{{singleEvents$ | async}}