How to do unsubscribe?

There is about the function
const sub: Subscription = this.usersService.allUsers
 .subscribe(users=> {
otherBehaviorSubject.next(users.filter(/*some filter function*/));
sub.unsubscribe(); // At this point constantly swearing that sub === undefined
});

I just need time to not value BehaviorSubject and immediately unsubscribe, how to do?
June 14th 19 at 20:08
2 answers
June 14th 19 at 20:10
at least sub.unsubscribe(); to put aside
const sub: Subscription = this.usersService.allUsers
 .subscribe(users=> {
otherBehaviorSubject.next(users.filter(/*some filter function*/));
});
sub.unsubscribe();
then I will unsubscribe not getting values - Cynthia.Donnelly commented on June 14th 19 at 20:13
so leave feedback when you receive this value bли on OnDestroy() - Toney.Padberg50 commented on June 14th 19 at 20:16
June 14th 19 at 20:12
Use take he chooses N elements from a sequence, it terminates and produces a runaround

this.usersService.allUsers
.take(1)
 .subscribe(users=> {
 otherBehaviorSubject.next(users.filter(/*some filter function*/));
 });

Find more questions by tags AngularJavaScript