Md.jahidul Islam February 2016

dispose/unsubscribe inside subscribe function block in rxjs

I've a subject called authenticated in _auth service.

I want to dispose/unsubscribe it if some condition fails so that this subscribe doesn't call when next value arrives in authenticated subject.

                this.sub = this._auth.authenticated
                .subscribe((loggedIn) => {
                    if (!loggedIn) {
                        this.sub.dispose(); // doesn't work because this.sub is null
                        this._location.replaceState('/');
                        this._auth.doLogout(); // emits value again in authenticated subject
                    }
                });

What is the rxjs-5 way of doing it?

Answers


Gerard Sans February 2016

You hold a reference to the observable Eg: obs$ and call obs$.unsubscribe();

Post Status

Asked in February 2016
Viewed 3,857 times
Voted 9
Answered 1 times

Search




Leave an answer