javascript - dispose/unsubscribe inside subscribe function block in rxjs -


i've subject called authenticated in _auth service.

i want dispose/unsubscribe if condition fails 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 null                         this._location.replacestate('/');                         this._auth.dologout(); // emits value again in authenticated subject                     }                 }); 

what rxjs-5 way of doing it?

you hold reference observable eg: obs$ , call obs$.unsubscribe();


Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -