Home Ask Login Register

Developers Planet

Your answer is one click away!

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._auth.doLogout(); // emits value again in authenticated subject

What is the rxjs-5 way of doing it?


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


Leave an answer

Quote of the day: live life