Unsubscribe observable in an Angular service

Discussão em 'Angular' iniciado por laprof, Dezembro 13, 2024.

  1. laprof

    laprof Guest

    I want to unsubscribe an observable in an angular service once a certain state is present. The unsubscribe should be executed within the subscription. Unfortunately the code below does not work.

    @Injectable()
    export class CartManagementUsecase {
    private unsubscribe = new Subject();

    public streamSession(): void {
    this.adapter
    .streamSession()
    .pipe(takeUntil(this.unsubscribe))
    .subscribe((session) => {
    if(session.session_state === SessionState.CLOSED) {
    this.unsubscribe.unsubscribe();
    }
    });
    }
    }

    Continue reading...

Compartilhe esta Página