Unsubscribe from observed rxjs immediately

Can someone shed some light on how I immediately unsubscribe from the observed rxjs subscription? Observed from Angular 2 EventEmitter. When I receive the event, I want to unsubscribe. The problem here is unsubscribing inside the function block. I feel like this is the wrong approach:

this.subscription = observable.subscribe((result: any) => { // do something // **unsubscribe** }); 

thanks

+5
source share
1 answer
 observable.first().subscribe(....)` 

end the subscription after the first event.

+14
source

Source: https://habr.com/ru/post/1258139/


All Articles